For this scenario, I have an HTML page with some AngularJS directives, controllers, etc.
Something like that:
<html> <body> <div ng-controller="myCtrl"> <ul><li ng-repeat="item in items">{{item.name}}</li></ul> </div> <div class="placeholder"> ...new HTML here... </div> </body> </html>
Please note that there is no ng-app directive on the page. I do not rely on automatic loading, but I use the manual boot method.
angular.bootstrap(document, ['myApp']);
First, I create a module that will be loaded into the document. Then, when the dynamically defined list of dependencies loads, I attach some services, controllers, etc. Once everything is ready, I call the bootstrap method.
All this works fine until JavaScript outside AngularJS is added to the DOM in ...new HTML here... New HTML is not processed by AngularJS.
I understand that you need to call $scope.$apply() or $digest() or something to make AngularJS recognize the new HTML. However, in my example, there is no controller around the new HTML code. The incoming HTML may look like this:
<div ng-controller="myOtherCtrl"> <h2>{{model.title}}</h2> </div>
In other words, it relies on another controller in the application module.
- I cannot call the
angular.bootstrap method angular.bootstrap because the page is already linked. - I cannot call
$scope.$apply from inside the controller, because the thing is that the controller code is not called. - I see no way to get a link to the controller to reapply or update it.
I read the message Ifeanyi Isitor lazy loading post and the message
javascript angularjs
jedatu Dec 18 '13 at 6:59 2013-12-18 06:59
source share