从ngRoute迁移到ui.router

时间:2017-01-29 19:45:40

标签: javascript angularjs angular-ui-router ngroute

我遇到从ngroute迁移到ui.router的问题:

使用ngroute我有几个角度文件:

module.js

angular.module('betTogether', ['ngRoute']);

route.js

angular.module('betTogether').config(['$routeProvider',
    function (
        $routeProvider
    ) {
          $routeProvider.
              when('/descriptionBets', {
                  templateUrl: 'descriptionBets',
                  controller: 'descriptionBetsCtrl'
              }).
              when('/normalBets', {
                  templateUrl: 'normal',
                  controller: 'normalBetsCtrl'
              }).
              when('/addBet', {
                  templateUrl: 'addBet',
                  controller: 'addBetCtrl'
              }).
              otherwise({
                  redirectTo: '/descriptionBets'
              });
}]);

normalBets.js

angular.module('betTogether').controller('normalBetsCtrl', [
'$scope','$http',

function($scope,$http){

    $scope.typeBetsImages = [{link: "images/basketball.png", title:"basketball"},
                {link: "images/tenis.png", title: "tenis"},
                {link: "images/volleyball.png", title: "volleyball"},
                {link: "images/football.png", title:"football"}
    ];

    $http.get("/normalBets").success(function(data){
        $scope.normalBets = data;
    });

}]);

......和其他控制器。一切正常。 现在我想迁移到ui-router。所以我改变了module.js和route.js:

module.js

angular.module('betTogether', ['ui.router']);

route.js

angular.module('betTogether').config(['$stateProvider', '$urlRouterProvider', function($stateProvider, $urlRouterProvider){
                // For any unmatched url, send to /business
                $urlRouterProvider.otherwise("/descriptionBets")

                $stateProvider
                        .state('descriptionBets', {//State demonstrating Nested views
                            url: "/descriptionBets",
                            templateUrl: "descriptionBets",
                            controller: "descriptionBetsCtrl"
                        })
                        .state('normalBets', {//nested state [products is the nested state of business state]
                            url: "/normalBets",
                            templateUrl: "normal",
                            controller: "normalBetsCtrl"
                        })
                        .state('addBet', {//nested state [services is the nested state of business state]
                            url: "/addBet",
                            templateUrl: "addBet",
                            controller: "addBetCtrl"
                        });

            }]);

它不起作用。我有错误:

Error: [$injector:nomod] http://errors.angularjs.org/1.3.10/$injector/nomod?p0=betTogether angular.min.js:6:417

......它适用于每个控制器的第一行。

有人可以帮助我吗?

PS:对不起我的英语,希望你能理解所有。

1 个答案:

答案 0 :(得分:3)

检查<script>index.html次导入的顺序。可能是您在ui-router模块之后添加了betTogether模块,而它应该在它之前,因为betTogether取决于ui.router