gpt4 book ai didi

javascript - Angular 缺少 resumeBootstrap 函数

转载 作者:塔克拉玛干 更新时间:2023-11-02 22:14:50 24 4
gpt4 key购买 nike

我目前正在尝试使用 RequireJS 设置一个新的 AngularJS 项目。我从 angularjs-requirejs-seed 开始项目。我过去曾使用 angular/require 完成过一个项目,但我还无法使其以“NG_DEFER_BOOTSTRAP”方式工作。

这是我的 main.js 文件,

'use strict';

require.config({
paths: {
jquery: "bower_components/jquery/dist/jquery",
angular: "bower_components/angular/angular",
angularRoute: "bower_components/angular-route/angular-route.min",
angularMocks: "bower_components/angular-mocks/angular-mocks.min",
text: "bower_components/requirejs-text/text",
compApp: "components/app",
},
shim: {
'angular' : {'exports' : 'angular'},
'angularRoute': ['angular'],
'angularMocks': {
deps:['angular'],
'exports':'angular.mock'
}
},
priority: [
"angular"
]
});

//http://code.angularjs.org/1.2.1/docs/guide/bootstrap#overview_deferred-bootstrap
window.name = "NG_DEFER_BOOTSTRAP!";

require([
'angular',
'compApp/app'
], function(angular, app) {
var $html = angular.element(document.getElementsByTagName('html')[0]);

angular.element().ready(function() {
angular.resumeBootstrap([app['name']]);
});
});

当我运行它时,我在 resumeBoostrap 行收到错误 undefined is not a function。当我调试应用程序并在 resumeBootstrap 行上设置断点时,我发现 angular 缺少 resumeBootstrap 方法。但是 window.name 正确显示 NG_DEFER_BOOTSTRAP。此外,如果我删除 resumeBoostrap 方法并只执行 angular.bootstrap 然后应用程序工作,告诉我其他一切都很好。

这是我的 html 文件,

<!DOCTYPE html>
<!--[if lt IE 7]> <html class="no-js lt-ie9 lt-ie8 lt-ie7"> <![endif]-->
<!--[if IE 7]> <html class="no-js lt-ie9 lt-ie8"> <![endif]-->
<!--[if IE 8]> <html class="no-js lt-ie9"> <![endif]-->
<!--[if gt IE 8]><!--> <html class="no-js"> <!--<![endif]-->
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title></title>
<meta name="description" content="">
<meta name="viewport" content="width=device-width, initial-scale=1">

<!-- Place favicon.ico and apple-touch-icon.png in the root directory -->

<link rel="stylesheet" href="css/normalize.css">
<link rel="stylesheet" href="css/main.css">
<script src="js/modernizr.min.js"></script>
</head>

<body>
<!--[if lt IE 7]>
<p class="browsehappy">You are using an <strong>outdated</strong> browser. Please <a href="http://browsehappy.com/">upgrade your browser</a> to improve your experience.</p>
<![endif]-->

<h1>AngularJS + RequireJS</h1>
<ul class="menu">
<li><a href="#/view1">view1</a></li>
<li><a href="#/view2">view2</a></li>
</ul>

<div ng-view></div>

<script data-main="main" src="bower_components/requirejs/require.js"></script>
</body>
</html>

最佳答案

根据 angular documentation for bootstrap :

If window.name contains prefix NG_DEFER_BOOTSTRAP! when angular.bootstrap is called, the bootstrap process will be paused until angular.resumeBootstrap() is called.

angular.resumeBootstrap() takes an optional array of modules that should be added to the original list of modules that the app was about to be bootstrapped with.

这是我在 require js 应用程序中延迟 Angular 初始化的代码片段:

window.name = "NG_DEFER_BOOTSTRAP!";

define(['angular', 'domReady', 'app'], function(ng, domReady){
domReady(function(document){
ng.bootstrap(document, ['app']);
ng.resumeBootstrap();
})
});

关于javascript - Angular 缺少 resumeBootstrap 函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25668958/

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