What is this warning on the console using Angularjs?

Asked

Viewed 115 times

1

I’m trying to run a simple code with angular and this warning stop on the console:

Uncaught Error: [$injector:modulerr] http://errors.angularjs.org/1.4.2/$injector/modulerr? P0=app&p 1=Error%3A%20%... angular.js:38

Follow my app.js file:

var app = angular.module('app', []);

My controller:

app.controller('appController', function ($scope, $http, $stateParams){

$scope.pegaCep = function (data) {
    $http.get("php/pegaCep.php?cep="+$stateParams.cep).success(function (data){
        console.log(data);
    });
 }

});

Yes, the warning talk about the wrong controller injection, but as wrong?

  • you’re minifying the files?

  • What do you mean? angular.js is using the web address: <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.2/angular.min.js"></script>

  • Minificado is the file that (by convention) has the extension .min.js, where the file is compressed. http://answall.com/questions/15019/qual-a-diff%C3%A7a-between-use-of-files-js-e-min-js

  • No, I’m not using min.js

  • You only own a single state?

  • The ["ngRoute"] on the call of your module it doesn’t just work by adding this plugin: https://ajax.googleapis.com/ajax/libs/angularjs/1.2.1/angular-route.min.js ? Did you? I could be mistaken, I’m not very experienced in Angular, but I imagined this.

  • I already took the ngRoute but it didn’t help. Funny, because I have another application with angular and doesn’t have this problem.

  • Another complimentary remark to @Samirbraga, I don’t know why you’re using the ui-router and ngRoutetogether... it’s very contradictory.

  • @Gustavosevero You only have one state?

  • try adding this script https://docs.angularjs.org/api/ngRoute

  • Yes, just a state... However, I think it would not be necessary to put state, because I only have the index.html

  • I was advised to use ui-route because ngRoute is being discontinued. @Davidschrammel.

  • Is there another way to pass parameters? Because if I take the $stateParams, the problem comes out.

  • I got... I took the route, the app.config and everything else, I left only the first line. See the modification in the post.

Show 9 more comments

1 answer

3


You are using a minified version of Angularjs, so errors are not being displayed in extended format.

In a quick analysis, it seems to me that you are using the injector $stateParams, that belongs to the module UI router from Angular UI library. However, your statement of application is not including.

To solve the problem:

  • Include a mention of the Router UI module, using for example a CDN:

https://cdnjs.cloudflare.com/ajax/libs/angular-ui-router/0.2.15/angular-ui-router.js

  • Declare the dependency on initialization of your application:

    var myApp = angular.module('app', ['ui.router']);

  • What would be the CDN version of angular? Now I took out $stateParams and stopped giving error... But you mean to use it I have to import the ui-route, that’s it?

  • @Gustavosevero There are several Cdns for Angular; for version 1.4.5 the official Urls are https://ajax.googleapis.com/ajax/libs/angularjs/1.4.5/angular.min.js, and non-minified version https://ajax.googleapis.com/ajax/libs/angularjs/1.4.5/angular.js

  • @Gustavosevero Yes, if you want to use the injector $stateParams you will need to include mentions to the ui-route module.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.