Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does this Angular controller throw "Error: Unknown provider: nProvider <- n"?

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).

like image 957
Chaddeus Avatar asked Mar 30 '13 16:03

Chaddeus


2 Answers

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.

like image 64
Chaddeus Avatar answered Oct 26 '22 12:10

Chaddeus


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/

like image 28
charlietfl Avatar answered Oct 26 '22 12:10

charlietfl