I am not using scope outside of the controller so I am confused why I keep getting the error:
Uncaught ReferenceError: $scope is not defined
It is from line 5 which is the "pollApp.controller" line.
(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;
}
}
}]);
I also checked that Angular is loading fine. Any help would be awesome. Thanks.
当在DI array annotation
使用dependency
,您需要在数组内部将其用引号括起来,例如'$scope'
,然后可以在控制器的factory
函数内(例如, $scope
这些依赖项的实例
pollApp.controller('choiceCtrl', ['$scope', function ($scope) {
pollApp.controller('choiceCtrl', ['$scope',
缺少引号
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.