【问题标题】:migrating from ngRoute to ui.router从 ngRoute 迁移到 ui.router
【发布时间】:2017-06-14 23:27:36
【问题描述】:

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

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

模块.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:

模块.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:对不起我的英语,希望你能理解所有。

【问题讨论】:

    标签: javascript angularjs angular-ui-router ngroute


    【解决方案1】:

    index.html 中检查<script> 导入的顺序。很可能是您在betTogether 模块之后包含了ui-router 模块,而它应该在它之前,因为betTogether 依赖于ui.router

    【讨论】:

    • 我将 angular 和 ui-router 脚本放在导入的开头 - 它可以工作。所以,非常感谢:)
    猜你喜欢
    • 2017-07-21
    • 1970-01-01
    • 1970-01-01
    • 2015-07-05
    • 1970-01-01
    • 2012-12-04
    • 2011-04-26
    • 2015-07-23
    • 2020-05-31
    相关资源
    最近更新 更多