Skip to content Skip to sidebar Skip to footer

After Including Ui.router Application Stopped To Work

While i was using ngRoute my application was fully working, but now i have switched to angular-ui-router and app doesn't work. this is app.js file var app = angular.module('app', [

Solution 1:

I think that the problem is that you're not assigning a name to your controller.

So try something like this

var app = angular.module('app');

    app.controller('TodoCtrl', TodoCtrl);

    // minification safe injection
    TodoCtrl.$inject = ['$scope', '$timeout', 'todoFactory', '$state', '$stateParams');

    functionTodoCtrl ($scope, $timeout, todoFactory, $state, $stateParams) {

        console.log('test');
        if(!$stateParams.pageNumber){
            $scope.currentPage = 1;
        } else {
            $scope.currentPage = $stateParams.pageNumber;
        }
        console.log($scope.currentPage);
        getData();

        //get another portions of data on page chang$locationed$scope.pageChanged = function () {
            $state.go("details", {pageNumber: $scope.currentPage });
        };

        /**
         * Get list of todos with pagination
         */functiongetData() {
            todoFactory.index($scope.currentPage).then(function (data) {
                $scope.totalItems = data.paging.count;
                $scope.itemsPerPage = data.paging.limit;
                $scope.todos = data.Todos;
            });
        }
    };

In addition to that I highly recommend to read John Papas Angular Styleguide It will teach you things like avoiding $scope and using the controllerAs syntax

Post a Comment for "After Including Ui.router Application Stopped To Work"