Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

Can you please assist in finding why $Scope.notify is undefined, infact the other function is working totally fine.

services.js [ postmain and allresults are working fine but not notifyadd??]

            services.factory('PFactory', ['$resource', function ($resource) {
                alert("I am here service");

                return  {
                    postmain: $resource('/ngdemo/web/posts', {}, {
                        query: {method: 'GET', isArray: true },
                        create: {method: 'POST'}
                    }),
                    allresults: $resource('/ngdemo/web/posts/result/:tag', {}, {
                        query: {method: 'GET', params: {tag: '@tag'} },
                        create: {method: 'POST'}
                    }),
                    notifyadd: $resource('/ngdemo/web/notify', {}, {
                        query: {method: 'GET', isArray: true },
                        create: {method: 'POST'}
                    }),

                    allnotifications: $resource('/ngdemo/web/posts/result/:key', {}, {
                        query: {method: 'GET', params: {tag: '@key'} },
                        create: {method: 'POST'}
                    })};
            }]);

CONTROLLER.js

            app.controller('MyCtrl2', ['$scope', 'PFactory', '$location', function ($scope, PFactory, $location) {

                $scope.createPost = function () {

                    PFactory.postmain.create($scope.UserPost)
                    $scope.allposts.push($scope.UserPost);

                    $scope.UserPost = "";

                }

                $scope.notify = function () {
                   console.log("in notify" + $scope.Notify.secEmail);
                    PFactory.notifyadd.create($scope.Notify)

                }

            }]);

HTML file:

            <form role="form">
                                    <div class="row">
                                        <div class="col-xs-8 col-md-4">
                                            <div class="form-group">
                                                <input type="text" ng-model='Notify.secEmail'
                                                       placeholder="Email of the person who can help?" class="form-control"
                                                       ></div>
                                        </div>
                                                <div class="col-xs-8 col-md-4">
                                                    <div class="form-group">
                                                        <input type="text" ng-model="Notify.message"
                                                               placeholder="Enter a Message or Phone number" class="form-control"
                                                               >
                                                       <!-- <input type="hidden" ng-model="Notify.loggedInEmail" ng-value="{{ result.first_name }}" />
                                                        <input type="hidden" ng-model="Notify.postId" ng-value="{{ post.id }}" />
                                                        <input type="hidden" ng-model="Notify.destEmail" ng-value="{{ post.userEmail }}" />-->
                                                    </div>
                                                </div>
                                        <div class="col-xs-6 col-md-3">
                                            <button class="btn btn-danger" ng-click="notify()" type="button">
                                                Notify
                                            </button>
                                            <!--<input type="submit" ng-click='notify()' value="Notify"
                                                   class="btn btn-danger btn-block btn-sm" tabindex="7">-->
                                        </div>
                                    </div>
                                </form>

ERROR I am getting is:

Error: $scope.Notify is undefined $scope.notify@http://pingle.com:8080/ngdemo/js/controllers.js:213 

Same works with postmain create function but not with Notify!! Any idea?

share|improve this question
    
I see the function notify() but not the object Notify - where has it been defined? As the error states, the object is undefined - which is correct. I can't see any definition of it, yet you use its properties in your view (and also seem to submit an HTTP POST request using that object) –  callmekatootie Apr 1 at 10:05
    
I am capturing the value entered in input text as "<input type="text" ng-model="Notify.message"", Notify is my java object. and when function notify is called, it says undefined, however if you see same is working fine for createPost method and it doesnt throw any error for "UserPost" –  AngryJS Apr 1 at 10:09
    
Actually this view code is under ng-repeat "<ul ng-repeat="post in allposts" class="timeline">"! I just tried above code outside ng-repeat and it worked. is there any issue with objects and calling new post inside ng-repeat which I am missing? –  AngryJS Apr 1 at 10:11
    
Just define $scope.Notify in your controller. –  Beyers Apr 1 at 10:15
    
I tried with $scope.notify = function () { console.log("in notify" + $scope.Notify.secEmail); PFactory.notifyadd.create($scope.Notify) $scope.Notify = ""; } –  AngryJS Apr 1 at 10:23

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.