我正在通過angularJS的基本知識介紹它是如何手動引導的。我遇到了不同的方法,發現this approach是最合適的。瞭解angularJS的步驟明智的手動引導
angular.element(document).ready(function(){
angular.bootstrap(document,['myapp'])
})
繼續前進,我碰到了this another way which breaks it to basics。根據我的理解,我已經評論了代碼,但是有人可以向我詳細解釋一下情況如何。
window.onload = function(){
var $rootElement = angular.element(window.document);
var modules = [
'ng', // angular module
'myApp', // custom module
// what are we trying to achieve here?
function($provide){
$provide.value('$rootElement',$rootElement)
}
];
var $injector = angular.injector(modules); // one injector per application
var $compile = $injector.get('$compile'); // Compile Service: it traverses the DOM and look for directives and compile and return linking function. No accecess to scope
var compositeLinkFn = $compile($rootElement); // collection of all linking function. Here scope is getting accessed
var $rootScope = $injector.get('$rootScope'); // Hold of the rootscope
compositeLinkFn($rootScope);
$rootScope.$apply();
}
另外,請隨時通過提出更多的方法和改進來啓發我更多關於此主題。
我想也許你的問題是過於寬泛。你有什麼機會縮小它? – hkBst
@hkBst:不知道該怎麼辦這個問題。我想了解發生了什麼,我已經提供了所有步驟。這是我一直保持這種恩惠:( –