gpt4 book ai didi

javascript - 警告 : Tried to load angular more than once during page load

转载 作者:行者123 更新时间:2023-12-03 06:37:29 27 4
gpt4 key购买 nike

我在我的一个项目中收到此警告。这在调用我的后端 api 时会导致问题,因为它调用了 api 两次。我已经尝试过之前在论坛上发布的关于相同查询的解决方案,但我无法解决这个问题。如果有人能帮助我解决这个问题,那就太好了。下面是 app.js 和 index.html 文件。

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Qwinix Aptitude Test</title>
<meta name="description" content="">
<meta name="viewport" content="width=device-width">
<!-- Place favicon.ico and apple-touch-icon.png in the root directory -->
<!-- build:css(.) styles/vendor.css -->
<!-- bower:css -->
<link rel="stylesheet" href="bower_components/bootstrap/dist/css/bootstrap.css" />
<!-- endbower -->
<!-- endbuild -->
<!-- build:css(.tmp) styles/main.css -->
<link rel="stylesheet" href="styles/styles.css">
<link rel="stylesheet" type="text/css" href="styles/question/normalize.css" />
<link rel="stylesheet" type="text/css" href="styles/question/demo.css" />
<link rel="stylesheet" type="text/css" href="styles/question/component.css" />
<!-- <link rel="stylesheet" type="text/css" href="bower_components/font-awesome/css/font-awesome.min.css" /> -->
<!-- <link rel="stylesheet" type="text/css" href="bower_components/semantic/dist/semantic.css"> -->
<link rel="stylesheet" type="text/css" href="styles/scss/style.scss">
<!-- <link rel="stylesheet" type="text/css" href="components/angular-ui/build/angular-ui.css"> -->

<!-- endbuild -->
</head>

<body data-ng-view="" ng-app="onlineTestAngularApp">
<!-- build:js(.) scripts/vendor.js -->
<!-- bower:js -->
<script src="bower_components/jquery/dist/jquery.js"></script>
<script src="bower_components/angular/angular.js"></script>
<script src="bower_components/bootstrap/dist/js/bootstrap.js"></script>
<script src="bower_components/angular-animate/angular-animate.js"></script>
<script src="bower_components/angular-aria/angular-aria.js"></script>
<script src="bower_components/angular-cookies/angular-cookies.js"></script>
<script src="bower_components/angular-messages/angular-messages.js"></script>
<script src="bower_components/angular-resource/angular-resource.js"></script>
<script src="bower_components/angular-route/angular-route.js"></script>
<script src="bower_components/angular-sanitize/angular-sanitize.js"></script>
<script src="bower_components/angular-touch/angular-touch.js"></script>
<script src="bower_components/angular-local-storage/dist/angular-local-storage.js"></script>
<script src="bower_components/moment/moment.js"></script>
<script src="bower_components/humanize-duration/humanize-duration.js"></script>
<script src="bower_components/angular-timer/dist/angular-timer.js"></script>
<script src="bower_components/semantic/dist/semantic.js"></script>
<script src="bower_components/angular-fontawesome/dist/angular-fontawesome.js"></script>
<script src="bower_components/angular-drag-and-drop-lists/angular-drag-and-drop-lists.js"></script>
<!-- endbower -->
<!-- endbuild -->

<!-- build:js({.tmp,app}) scripts/scripts.js -->
<script src="scripts/app.js"></script>
<script src="scripts/config.js"></script>
<script src="scripts/controllers/main.js"></script>
<script src="scripts/controllers/about.js"></script>
<script src="scripts/controllers/registration.js"></script>
<script src="scripts/services/registration.js"></script>
<script src="scripts/controllers/question.js"></script>
<script src="scripts/controllers/feedback.js"></script>
<script src="scripts/services/feedback.js"></script>
<script src="scripts/services/question.js"></script>
<script src="scripts/controllers/index.js"></script>
<script src="scripts/controllers/instruction.js"></script>
<script src="scripts/services/admin.js"></script>
<script src="scripts/controllers/admin.js"></script>
<script src="scripts/my_jquery.ui.js"></script>
<script src="scripts/lib/angular-timer.js"></script>
<!-- endbuild -->
</body>
</html>

'use strict';

/**
* @ngdoc overview
* @name onlineTestAngularApp
* @description
* # onlineTestAngularApp
*
* Main module of the application.
*/
angular
.module('onlineTestAngularApp', [
'ngAnimate',
'ngAria',
'ngCookies',
'ngMessages',
'ngResource',
'ngRoute',
'ngSanitize',
'ngTouch',
'LocalStorageModule',
'config',
'timer'
])
.config(function ($routeProvider) {
$routeProvider
.when('/', {
templateUrl: 'views/registration.html',
controller: 'registrationCtrl',
controllerAs: 'registration'
})
.when('/instruction', {
templateUrl: 'views/instruction.html',
controller: 'instructionCtrl',
controllerAs: 'instruction'
})
.when('/question', {
templateUrl: 'views/question.html',
controller: 'questionCtrl',
controllerAs: 'question'
})
.when('/feedback', {
templateUrl: 'views/feedback.html',
controller: 'feedbackCtrl',
controllerAs: 'feedback'
})
.when('/admin', {
templateUrl: 'views/admin.html',
controller: 'adminCtrl',
controllerAs: 'admin'
})
.otherwise({
redirectTo: '/'
});
});

最佳答案

当我的 templateUrl 设置为空白字符串并且在嵌套 state 上没有定义其他模板时,出现此错误,如下所示。

app.config(['$stateProvider', '$urlRouterProvider', function ($stateProvider, $urlRouterProvider) {
$urlRouterProvider.otherwise('/');
$stateProvider
.state('main', {
abstract: true,
url: '',
templateUrl: '/app/main/wrapper.html'
})
.state('main.welcome', {
controller: '',
templateUrl: '', // Causes WARNING: Tried to load angular more than once.
url: '/'
});
}]);

'main.welcome' templateUrl 更改为模板路径后,我不再收到警告。

.state('main.welcome', {
controller: '',
templateUrl: '/app/main/welcome.html',
url: '/'
});

关于javascript - 警告 : Tried to load angular more than once during page load,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38126623/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com