2016-09-27 71 views
0

如何創建一個模塊,該模塊具有模板「Hello world」的指令,並在初始化網頁的同時將該模塊注入到基本模塊(應用程序)中,該指令應該編譯並附加到<body>如何創建一個簡單模塊來注入應用程序模塊?

angular.module('helloWorld',[]).provider(['helloWorld',function(ngModalView){ 

    return{ 
     $get : [function($compile, $scope){ 
      var tem = $compile('<hello-world></hello-world>')($scope); 
      //append this template to body 
     }] 
    }; 

}]); 

angular.module('helloWorld',[]).directive('helloWorld',[function(){ 
     return { 
      restrict: 'E',  
      replace: true, 
      template: '<div style="width=150px;height="150px">Hello world</div>' 
     }; 
}]); 

我需要在應用程序啓動時在模塊上運行。

angular.module('app',['helloWorld']); 
+0

給我們一些更多的信息或摘要,以供問題附着 – Thaadikkaaran

+0

一個示例代碼 – azad

+0

你的意思是模塊的延遲加載? – Thaadikkaaran

回答

0

每當角應用自舉,首先它會加載依賴性模塊(你的情況的「HelloWorld」),然後主模塊「的應用程序」將被加載。所以你不用擔心加載/運行相關模塊。

如果你正在考慮模塊的延遲加載,然後看看這個網址

https://oclazyload.readme.io/

相關問題