如何将角度引导程序延迟到服务电话之后 [英] How to delay angular bootstrap until after a service call
问题描述
我是angular的初学者.我需要进行多个Web服务调用,然后引导我的模型.我尝试将以下代码放入所有网络服务运行后执行的函数中.
I'm a beginner on angular. I've got a need to make multiple webservice calls and then bootstrap my model. I've tried placing the following code inside my function that is executed after all webservices have run.
var myApp = angular.module('myApp', [])
myApp.controller('Ctrl', ['$scope', function ($scope) {
$scope.obj = model
}]);
angular.element(document).ready(function () {
angular.bootstrap(document, ['myApp']);
});
但是我收到以下异常.
[$ injector:modulerr]由于以下原因,无法实例化模块myApp:[$ injector:nomod]模块'myApp'不可用!您可能拼错了模块名称,或者忘记了加载它.如果要注册模块,请确保将依赖项指定为第二个参数.
[$injector:modulerr] Failed to instantiate module myApp due to: [$injector:nomod] Module 'myApp' is not available! You either misspelled the module name or forgot to load it. If registering a module ensure that you specify the dependencies as the second argument.
我的代码仍然有效,但是我想摆脱异常,更重要的是,了解延迟引导时应如何构造角度代码.
My code still works, but I want to get rid of the exception and more importantly learn how the angular code should be structured when the bootstrapping is delayed.
我不知道这是否会有所帮助,但以防万一.
I don't know if this will help, but I'm including it in case.
<div ng-app ng-controller="Ctrl">
<div ng-repeat="o in obj track by $index">
</div>
<input id="Model" type="hidden" value="{{obj}}" />
</div>
推荐答案
我从较早的尝试中发现可以将其添加到html标记中.
I found from earlier attempts to get it working that I added the following to the html tag.
ng-app="myApp"
当我删除它时,我的错误消失了.我相信这是执行自动引导的方式,但是由于我需要延迟引导,所以这会引起问题.这是有关该指令的更多信息的链接
When I removed it my error went away. I believe this is how you would perform automatic bootstrapping, but since I needed delayed bootstrapping it was causing issues. Here is a link for more information on the directive
如果更熟悉angular的人可以验证我的理解,我将不胜感激.谢谢阿伦的小提琴.
If someone more familiar with angular could verify my understanding I would appreciate it. Thank you Arun for your fiddle.
这篇关于如何将角度引导程序延迟到服务电话之后的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!