【问题标题】:AngularJS routing "WARNING: Tried to load angular more than once" loopAngularJS路由“警告:尝试多次加载角度”循环
【发布时间】:2015-07-24 17:29:10
【问题描述】:

我正在尝试制作一个应用程序来学习使用 AngularJS 和 rails。只有当我尝试使用角度路由时,我才会在无限循环中在控制台“警告:尝试多次加载角度”中打印出来。

如果遵循此tutorial 直到从那里出现问题,我已经在 Stackoverflow 上进行了很多搜索,但找不到解决我的问题的方法。

app.js

var app = angular.module('Deadlines', ['ngRoute', 'templates'], function($routeProvider, $locationProvider) {
  $routeProvider.when('/', {
    templateUrl: 'home.html',
    controller: 'HomeCtrl'
  }).otherwise( { redirectTo: '/'} );

  $locationProvider.html5Mode(true);
});

【问题讨论】:

    标签: angularjs ruby-on-rails-4


    【解决方案1】:

    警告显示您添加了多个 Angular js 库。最好删除任何一个角度库。

    【讨论】:

    • 我找不到任何可能导致问题的 angular 副本,我找到了解决我的问题的另一个解决方案,这也表明这不是问题所在。感谢您的建议。
    【解决方案2】:

    我已经通过使用 AngularUI Router 来解决我的问题。当我尝试仅使用 HTML 和 Angular 重新创建问题时,我发现此问题并未发生。所以它与rails和Angular的组合有关。我无法解释为什么 AngularUI Router 是我的问题的解决方案,因为我仍然是菜鸟,但它有效,我可以继续学习构建应用程序。

    app.js

    angular.module('Deadlines', ['ui.router', 'templates'])
        .config([
            '$stateProvider',
            '$urlRouterProvider',
            function($stateProvider, $urlRouterProvider) {
                $stateProvider
                .state('home', {
                    url: '/',
                    templateUrl: 'home.html',
                    controller: 'HomeCtrl',
                })
                $urlRouterProvider.otherwise('/');
            }])
        .config(["$locationProvider", function($locationProvider) {
          $locationProvider.html5Mode(true);
      }]);
    

    这是我当前的 app.js,供面临同样问题的人使用

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-06-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-09-12
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多