[英]Why does Angular say “Uncaught ReferenceError: $scope is not defined”?
我没有在控制器之外使用作用域,所以我很困惑为什么一直出现错误:
Uncaught ReferenceError: $scope is not defined
它来自第5行,即“ pollApp.controller”行。
(app.js)
var pollApp = angular.module('myApp', ['ui.router']);
pollApp.controller('choiceCtrl', [$scope, function ($scope) {
$scope.choices = [{body: "test"}]; //just for testing
$scope.addChoice = function () {
//add new choice
if ($scope.choiceBody) {
$scope.choices.push({
body: $scope.choiceBody
});
$scope.choiceBody = null;
}
}
}]);
我还检查了Angular是否可以正常加载。 任何帮助都是极好的。 谢谢。
当在DI array annotation
使用dependency
,您需要在数组内部将其用引号括起来,例如'$scope'
,然后可以在控制器的factory
函数内(例如, $scope
这些依赖项的实例
pollApp.controller('choiceCtrl', ['$scope', function ($scope) {
pollApp.controller('choiceCtrl', ['$scope',
缺少引号
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.