angular load template from url and compile inside div

前端 未结 3 1935
野性不改
野性不改 2021-02-02 13:46

As I\'m new to Angular JS I was wondering how could I load an external template and compile it with some data into the targeted div.

For instance I have thi

3条回答
  •  说谎
    说谎 (楼主)
    2021-02-02 14:21

    Let's say I have this index.html:

      
            
                   
                       
                
                
             
    
    

    And I have a template file "tpl/ng.menu.tpl" with only these 4 lines:

    
    

    My directives mapping "js/directives.js":

    angular.module('myApp',['myApp.directives']);
    var myModule = angular.module('myApp.directives', []);
    
    myModule.directive('mainmenu', function() {
        return { 
            restrict:'E',
            replace:true,
            templateUrl:'tpl/ng.menu.tpl'
        }
    });
    

提交回复
热议问题