Skip to content Skip to sidebar Skip to footer

Angular Showing Typeerror: Cannot Read Property 'state' Of Undefined

I am trying to learn routing by adding routing to a specific page in my rails app using angular which will replace ajax. Below is the console error am getting. Uncaught Error: [$i

Solution 1:

Problem is with definition of config function. If you use array app.config([]) that means that you write safe code for the dependencies prepared for minification. Syntax is:

app.config(['$arg1', '$arg2', function ($arg1, $arg2) {
   }]);

So when code is minified you will get something like:

app.config(['$arg1', '$arg2',function(a,b) {}]);

In your example in app.js change config to following code if you want to write code safe for minification (if you are not using ng-annotate):

app = angular.module("testApp", ['ui.router']);

app.config(['$stateProvider','$urlRouterProvider',
    function ($stateProvider, $urlRouterProvider) {
        $stateProvider
            .state('mylistings', {
                url: '/mylistings',
                templateUrl: '/views/mylistings.html',
                controller: 'dashboardCtrl'
            });
    }
]);

app.controller('dashboardCtrl', function ($scope, $http, $stateParams) {
  $scope.testing="testdata"
});

or you can remove [] from config function :

app.config(function ($stateProvider, $urlRouterProvider) {
 ...
}):

Post a Comment for "Angular Showing Typeerror: Cannot Read Property 'state' Of Undefined"