gpt4 book ai didi

javascript - angular.bootstrap 和 angular ui-router 不启动 Controller

转载 作者:行者123 更新时间:2023-11-30 17:05:50 25 4
gpt4 key购买 nike

我正在从 Trigger.io 切换现有的 AngularJS 移动应用程序到 Cordova,因为它为我正在构建的东西提供了更好/更多的插件。

Cordova 要求我的应用程序在 deviceready event 之后加载被解雇了。我的应用程序构建在 ionic 框架之上,它们为此事件提供了一个包装器 (window.ionic.Platform.ready)。我认为它会像从我的 HTML 中删除 ng-app 一样简单,并在设备准备就绪时引导我的应用程序。唉……

我遇到了一些奇怪的事情。我正在使用 ui-router处理我的状态,它们在 $stateChangeStart 中被触发,但链接到该状态的 Controller 根本不会被触发。

我做了两个 Plunkrs 作为例子;

  • first one使用 ng-app 并完美运行
  • second one使用 angular.bootstrap,但从不使用来 self 的 Controller 的 console.log 内容。

我是不是做错了什么?感谢您的帮助!

最佳答案

问题在于根元素的选择,您只需要通过 document.body 获取正文,而不是尝试将其检索为 document.getElementById('body') 不返回任何内容。

angular.element(document).ready(function () {
angular.bootstrap(document.body, ['myApp']);
});

Plnkr

关于javascript - angular.bootstrap 和 angular ui-router 不启动 Controller ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28054649/

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