Manually bootstrapping AngularJS and then getting the module -


generally, i'd following , there ng-app in html:

var myapp = angular.module("myapp", []);  myapp.controller("attributectrl", function ($scope) {     $scope.master = {         name: "some name"     }; }); 

however, need manually bootstrap angular because i'm using in part of app loaded via jquery's $.load(). if following:

main.js - page want use angular on being pulled in

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

and page being pulled in has it's own javascript:

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

this works, however, ideally, i'd controllers scoped @ module level. modified above code so

main.js

$("#form").load(contextpath + url, params, function() {     angular.bootstrap($("#angularapp", ["myapp"])); }); 

and then...

var app = angular.module("myapp"); // retrieve module  app.controller("attributectrl", function($scope) {   $scope.master = { name: "some name"}; }); 

retrieving module way doesn't seem work, though. doing wrong?

you cannot create controller after you've bootstrapped app. see the documentation angular.bootstrap.

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


Comments

Popular posts from this blog

jquery - How can I dynamically add a browser tab? -

node.js - Getting the socket id,user id pair of a logged in user(s) -

keyboard - C++ GetAsyncKeyState alternative -