javascript – AngularJS:’$scope未定义’

前端之家收集整理的这篇文章主要介绍了javascript – AngularJS:’$scope未定义’前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我一直在AngularJS中为此控制器代码获取’$scope not defined’控制台错误
angular.module('articles').controller('ArticlesController',['$scope','$routeParams','$location','Authentication','Articles',function($scope,$routeParams,$location,Authentication,Articles){
            $scope.authentication = Authentication;
        }
    ]);


$scope.create = function() { // THROWS ERROR ON THIS INSTANCE OF $SCOPE
    var article = new Articles({
        title: this.title,content: this.content
    });

    article.$save(function(response) {
        $location.path('articles/' + response._id);
    },function(errorResponse) {
        $scope.error = errorResponse.data.message;
    });
};

在我的AngularJS MVC文件中,我应该在哪里查找$scope未正确定义的问题?

解决方法

将该代码放在控制器内: –
angular.module('articles').controller('ArticlesController',Articles){
            $scope.authentication = Authentication;

$scope.create = function() { // THROWS ERROR ON THIS INSTANCE OF $SCOPE
    var article = new Articles({
        title: this.title,function(errorResponse) {
        $scope.error = errorResponse.data.message;
    });
};
        }
    ]);
原文链接:https://www.f2er.com/js/156218.html

猜你在找的JavaScript相关文章