$ scope.object是undefined angularjs

时间:2014-04-01 09:51:31

标签: angularjs angularjs-directive angularjs-scope angular-ui

你能帮忙找到为什么$ Scope.notify未定义,事实上其他功能完全正常。

services.js [postmain和allresults工作正常,但不是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文件:

            <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: $scope.Notify is undefined $scope.notify@http://pingle.com:8080/ngdemo/js/controllers.js:213 

与postmain创建函数相同但不与Notify一起使用!!有什么想法吗?

0 个答案:

没有答案