【问题标题】:WARNING: Tried to load angular more than once警告:尝试多次加载角度
【发布时间】:2015-05-17 09:42:37
【问题描述】:

我正在尝试在 angular.js (1.3.15) 中路由并遇到这两个错误:

错误消息

1-WARNING: Tried to load angular more than once.

2-angular.js:38Uncaught Error: [$injector:modulerr]
http://errors.angularjs.org/1.3.15/$injector/modulerr?p0=after_login&
p1=Err…0d%20(http%3A%2F
%2Flocalhost%3A49062%2FScripts%2Fangular.min.js%3A17%3A381)

我的模块.js

var after_login = angular.module("after_login", ['ngRoute', 'CrackWeb']);


after_login.config(['$routeProvider', function ($routeProvider) {

  $routeProvider.when('/groups',
                    {
                        templateUrl: 'Views/p1.cshtml',
                        controller: 'MyScripts/groups'
                    })
              .otherwise(
                        {
                            redirectTo: '/'
                        });
$locationProvider.html5Mode(true).hashPrefix('!');
}]);

在我编写的带有 ng-app 的 html 页面中。

p1.cshtml [部分]

<div class="col-md-9">
    <br />
      <input ng-model="check" id="ch"/>
        {{check}}
      <div ng-view></div>
</div>

谁能帮忙?

【问题讨论】:

  • 控制器怎么样?
  • after_login.controller('groups', function ($scope) { $scope.login = function (userName, pass) { alert(userName+pass); var url = '52.11.190.113/api/account/login'; $http.post(url, { email:userName, password:pass, deviceregistrationid: '67788' }) .success(function (data,$location){ alert("success"+" "+ data.message); }) ; } });
  • 您是否在 html 中添加了 ng-app="after_login" ??
  • 这是我添加的

标签: javascript angularjs html twitter-bootstrap


【解决方案1】:

在您提到的路线提供商中

$routeProvider.when('/groups', { templateUrl: 'Views/p1.cshtml', controller: 'MyScripts/groups' }) .otherwise( { redirectTo: '/' });

但是你没有默认路由

$routeProvider.when('/', { templateUrl: 'sometemplate', controller: 'somecontroller' });

因此它会一次又一次地尝试加载您的默认 HTML(大多数情况下为 index.html)并导致错误

【讨论】:

  • 否则我有({redirectTo: '/' });
  • 你必须提到/的模板和控制器,否则它会再次尝试加载你的index.html!!!
  • [code] $routeProvider.when('/', { templateUrl: 'Views/index.html', controller: 'MyScripts/login_controller' }) 我添加了这段代码它没有帮助跨度>
  • 你的 index.html 中有没有 angularjs 核心文件!!!如果可能的话,在你的问题中添加你的 index.html
  • 我之前没有添加,但根本没有帮助。
【解决方案2】:

您无法加载带有 cshtml 扩展名的页面!

其实你在尝试通过 ANGULAR ROUTING 加载页面 CSHTML 时就错了。 由于您无法单独加载此页面,因此无法通过 ANGULAR 路径加载。

所以如果你想加载一个页面 CSHTML 那么你必须在 MVC 中调用他的控制器 并通过“ActionResult”加载它。

【讨论】:

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