angular.bootstrap 和 angular ui-router 不启动控制器 [英] angular.bootstrap and angular ui-router not launching controllers
问题描述
我正在将现有的 AngularJS 移动应用从 Trigger.io 切换到 Cordova,因为它提供了为我正在构建的内容提供更好/更多的插件.
I'm in the process of switching an existing AngularJS mobile app from Trigger.io to Cordova, as it provides way better/more plugins for what I'm building.
Cordova 要求我的应用程序在 deviceready
事件 被触发.我的应用程序构建在 ionic 框架之上,它们为此事件提供了一个包装器 (window.ionic.Platform.ready
).我认为这就像从我的 HTML 中删除 ng-app
并在设备准备就绪时引导我的应用程序一样简单.唉……
Cordova requires my application to be loaded after the deviceready
event is fired. My application is built on top of the ionic framework, and they provide a wrapper (window.ionic.Platform.ready
) for this event. I thought it was going to be as simple as removing ng-app
from my HTML and bootstrap my app when the device is ready. Alas...
我遇到了一些奇怪的事情.我正在使用 ui-router 来处理我的状态,它们在 $stateChangeStart
,但链接到该状态的控制器根本不会被触发.
I came across something weird. I'm using ui-router to handle my states and they get triggered in the $stateChangeStart
, but the controller linked to that state does not get triggered at all.
我以两个 Plunkrs 为例;
I've made two Plunkrs as example;
- the first one uses
ng-app
and works perfectly - the second one uses
angular.bootstrap
, but neverconsole.log
s stuff from my controllers.
我在这里做错了吗?任何帮助表示赞赏!
Am I doing something wrong here? Any help is appreciated!
推荐答案
问题在于选择了 rootElement,您只需要通过 document.body
获取正文,而不是尝试检索它作为 document.getElementById('body')
不返回任何内容.
Issue is with the selection of rootElement, you need to just get the body via document.body
instead you are trying to retrieve it as document.getElementById('body')
which does not return anything.
angular.element(document).ready(function () {
angular.bootstrap(document.body, ['myApp']);
});
这篇关于angular.bootstrap 和 angular ui-router 不启动控制器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!