这个问题有点奇怪,可能很难把握,但我会尽量解释我可以。由于以前的版本不是真正的SPA,我不得不使用AngularJS来重写移动应用程序。这是一个JSP网站,它的样式适合使用ajax调用Lightbox,视图等的移动设备。现在,我必须为新的AngularJS应用程序创建新功能,并将其包含到以前的JSP版本中(angularJS版本尚未发布)。我不想这样做两次,所以我已经将AngularJS添加到旧版本。我在身上的标签上注册了一个应用程序,注册了一些控制器,除了一件事以外,一切都很好。我在我的app.js
文件中有以下内容。动态添加/注册一个AngularJS控制器没有路由
var oldMobile = angular.module('oldMobile', [
'flow'
])
.config(function ($controllerProvider) {
oldMobile.controller = $controllerProvider.register;
})
.controller('MainCtrl', function ($scope) {
console.log('MainCtrl'); // this is shown in the console
})
.controller('UploadCtrl', function ($scope) {
console.log('UploadCtrl'); // this is shown in the console
})
.controller('ProfileCtrl', function ($scope) {
console.log('ProfileCtrl'); // this is NOT shown in the console
});
现在,当原始视图负荷MainCtrl
和UploadCtrl
注册为他们的HTML内,但ProfileCtrl未注册,因为这是由被用户事件后,动态加载(灯箱点击提供的内容)。当我在HTML中注册了data-ng-controller="ProfileCtrl"
之后,没有任何内容被写入控制台时,控制器无法正常工作。我试图通过添加一个脚本标记到灯箱HTML注册这样的
<script>
angular.module("oldMobile").controller('ProfileCtrl');
</script>
但没有任何反应。如何让我的模块在Lightbox被调用时注册ProfileCtrl?
如果我没有解释清楚,请让我知道,我会加上我的描述。
预先感谢