1

I am a bit issue with angularjs, this issue have taken many answer and but I can't resolve this issues in my case.

Here this is my import in html

<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.16/angular.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.16/angular-animate.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.16/angular-aria.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.16/angular-route.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.16/angular-resource.min.js"></script>

App.js

angular.module('ngApp',['ngRoute'])
.config(['$routeProvider'], 
    function($routeProvider){ // Error here !

}).controller('ngAppHome',function ($scope){
  $scope.title = ""; 
});

Error (in chrome)

Failed to instantiate module ngApp due to:
Error: [ng:areq] http://errors.angularjs.org/1.3.16/ng/areq?p0=fn&p1=not%2...
    at Error (native)
    at https://ajax.googleapis.com/ajax/libs/angularjs/1.3.16/angular.min.js:6:417
    at Sb (https://ajax.googleapis.com/ajax/libs/angularjs/1.3.16/angular.min.js:19:510)
    at La (https://ajax.googleapis.com/ajax/libs/angularjs/1.3.16/angular.min.js:20:78)
    at Function.bb.$$annotate (https://ajax.googleapis.com/ajax/libs/angularjs/1.3.16/angular.min.js:175:178)
    at Object.e [as invoke] (https://ajax.googleapis.com/ajax/libs/angularjs/1.3.16/angular.min.js:36:147)
    at d (https://ajax.googleapis.com/ajax/libs/angularjs/1.3.16/angular.min.js:34:498)
    at https://ajax.googleapis.com/ajax/libs/angularjs/1.3.16/angular.min.js:35:117
    at q (https://ajax.googleapis.com/ajax/libs/angularjs/1.3.16/angular.min.js:7:322)
    at g (https://ajax.googleapis.com/ajax/libs/angularjs/1.3.16/angular.min.js:34:399

Thanks for your help

Vsplit
  • 1,988
  • 3
  • 15
  • 18

1 Answers1

5

config() expects a single argument, not 2. Either it's the callback function itself, or it's an array containing provider names, followed by the callback function:

angular.module('ngApp',['ngRoute']).config(function($routeProvider){ 
    ...
})

or

angular.module('ngApp',['ngRoute']).config(['$routeProvider', function($routeProvider) { 
    ...
}])

Given that your code won't resist to minification anyway, since you don't use the array syntax for your controller, I would use the first, simple one. Use ngAnnotate in your build to make your code minifiable.

JB Nizet
  • 678,734
  • 91
  • 1,224
  • 1,255