加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

手动引导AngularJS,然后获取模块

发布时间:2020-12-17 07:37:04 所属栏目:安全 来源:网络整理
导读:一般来说,我会执行以下操作,我的 HTML中将会有一个ng应用程序: var myApp = angular.module("myApp",[]);myApp.controller("AttributeCtrl",function ($scope) { $scope.master = { name: "some name" };}); 但是,我需要手动引导角度,因为我只是在我的应用
一般来说,我会执行以下操作,我的 HTML中将会有一个ng应用程序:
var myApp = angular.module("myApp",[]);

myApp.controller("AttributeCtrl",function ($scope) {
    $scope.master = {
        name: "some name"
    };
});

但是,我需要手动引导角度,因为我只是在我的应用程序的一部分,通过jQuery的$.load()加载.如果我执行以下操作:

main.js – 这是我想要使用角度的页面被拉入的地方

$("#form").load(contextPath + url,params,function() {
    angular.bootstrap($("#angularApp"));
});

然后被拉入的页面有它自己的javascript:

function AttributeCtrl($scope) {
  $scope.master = { name: "some name"};
}

但是,这个工作理想情况下,我希望我的控制器在模块级别被限定.所以我修改了上面的代码

main.js

$("#form").load(contextPath + url,function() {
    angular.bootstrap($("#angularApp",["myApp"]));
});

接着…

var app = angular.module("myApp"); // retrieve a module

app.controller("AttributeCtrl",function($scope) {
  $scope.master = { name: "some name"};
});

但是,以这种方式检索模块似乎不起作用.我做错了吗?

引导应用程序后,无法创建控制器.见 the documentation for angular.bootstrap.

You should call angular.bootstrap() after you’ve loaded or defined your modules. You cannot add controllers,services,directives,etc after an application bootstraps.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读