私は手動でブートストラップされた方法について、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:この質問ではどうすればよいか分かりません。私はフードの下で何が起こるのか理解したいと思います。私はすべてのステップを提供しました。それは、私はこれに恩恵を維持しているyの:( –