jsFiddle of the code:
<div ng-app="">
<div ng-controller="FirstCtrl">
<input type="text" ng-model="data.message" />
{{data.message + " world"}}
</div>
</div>
function FirstCtrl($scope) {
$scope.data = {
message: "Hello"
};
}
I am just starting to learn Angular using the videos on Egghead.io. Following along I got stuck on the 2nd video where John discusses controllers. It works in his video, fails on my machine.
the code is so basic I can't figure out what's throwing this error:
> Error: Unknown provider: nProvider <- n
> at Error (<anonymous>)
> at http://cdnjs.cloudflare.com/ajax/libs/angular.js/1.1.3/angular.min.js:29:36
> at Object.c [as get] (http://cdnjs.cloudflare.com/ajax/libs/angular.js/1.1.3/angular.min.js:26:310)
> at http://cdnjs.cloudflare.com/ajax/libs/angular.js/1.1.3/angular.min.js:29:121
> at c (http://cdnjs.cloudflare.com/ajax/libs/angular.js/1.1.3/angular.min.js:26:310)
> at d (http://cdnjs.cloudflare.com/ajax/libs/angular.js/1.1.3/angular.min.js:26:444)
> at Object.instantiate (http://cdnjs.cloudflare.com/ajax/libs/angular.js/1.1.3/angular.min.js:28:80)
> at http://cdnjs.cloudflare.com/ajax/libs/angular.js/1.1.3/angular.min.js:51:512
> at http://cdnjs.cloudflare.com/ajax/libs/angular.js/1.1.3/angular.min.js:43:67
> at n (http://cdnjs.cloudflare.com/ajax/libs/angular.js/1.1.3/angular.min.js:7:43)
This error gets thrown if I use the google CDN as well (from the error, I thought perhaps it was the cdn's fault).
Turns out the problem was that my scripts were being minified, and the minifier was changing the name of the $scope variable. The Angular.js docs do mention how to minify Angular code.
Only problem in fiddle demo is setting for code to run within load handler.
Anguar can't find your controller function when it tries to parse the DOM
working version , simply change onload
in top left
http://jsfiddle.net/TCT8n/3/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With