警告:尝试多次加载角度.角JS [英] WARNING: Tried to load angular more than once. Angular JS

查看:34
本文介绍了警告:尝试多次加载角度.角JS的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在运行 Grunt Build 后尝试查看我的应用程序.我使用 grunt serve:dist 来查看所有生产就绪的构建,但在浏览器中我得到一个无限循环:

I am trying to view my app after running Grunt Build. I use grunt serve:dist to see all production ready build but in the browser I get an infinite loop saying:

警告:尝试多次加载角度.

WARNING: Tried to load angular more than once.

我已经读过这是因为连接后 TemplateURL: 可能是错误的.如这篇文章:尝试多次加载 Angular

I have read this occurs because the TemplateURL: may be wrong after concatenation. As in this post: Tried to Load Angular More Than Once

但是我该如何解决这个问题?这是我的 app.js

But how do I fix this? Here is my app.js

/* global libjsapp:true */


'use strict';

var libjsapp = angular.module('libjsApp', [
  'ngCookies',
  'ngResource',
  'ngSanitize',
  'ngRoute'
]);

libjsapp.config(['$routeProvider', function ($routeProvider, $locationProvider) {
    $routeProvider
      .when('/', {
        templateUrl: 'views/posts.html',
        controller: 'PostsCtrl'
      })
      .otherwise({
        redirectTo: '/'
      });
  }]);

推荐答案

就我而言,这是由于以下 html 代码:

In my case this was due to the following html code:

<!doctype html>
<html>
<head>
  <meta charset="utf-8">
  <title>Testapp</title>
</head>

<body ng-app="testApp">

  <main ui-view>

  <script src="bower_components/jquery/jquery.js"></script>
  <script src="bower_components/angular/angular.js"></script>
  <script src="bower_components/angular-ui-router/release/angular-ui-router.js"></script>

  <script src="scripts/main.js"></script>
</body>

</html>

如您所见,

并未关闭.这导致了我的'警告:尝试多次加载角度.' 问题.

As you can see, the <main> is not closed. This led to my variant of 'WARNING: Tried to load angular more than once.' issue.

这篇关于警告:尝试多次加载角度.角JS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆