I'm trying to setup angular in mu app with really basic code, but it keeps giving me the following error:
Uncaught ReferenceError: $scope is not defined
What I have is the following:
<!DOCTYPE html>
<html ng-app="test">
<head>
<!-- Other JS files here including jQuery!! -->
<script src="~/Scripts/angular.js" type="text/javascript"></script>
</head>
<script src="~/Scripts/angular.js" type="text/javascript"></script>
</html>
In app.js
I have:
var blaat11 = angular.module('test', []);
blaat11.controller('TestController', [$scope, function ($scope) {
var aa = $scope.test;
}]);
But I'm getting the error I posted earlier. I want to inject services into my controller like that. I've done it before like this and never had any trouble with it.
Anyone any idea why it isn't working?
答案 0 :(得分:3)
Wrap the $scope
in quotes. This is used for mapping of the Dependency injections in case of minifying the code. As the $scope
outside of the controller is not defined, the error is thrown.
blaat11.controller('TestController', ['$scope', function($scope) {