How to conditionally apply a template via custom Angular directives?

后端 未结 6 806
攒了一身酷
攒了一身酷 2020-12-29 02:37

DEMO

Consider the following directive:

angular.module(\'MyApp\').directive(\'maybeLink\', function() {
  return {
    replace: true,
    s         


        
6条回答
  •  伪装坚强ぢ
    2020-12-29 03:10

    You might be able to use a template function. According to the docs:

    You can specify template as a string representing the template or as a function which takes two arguments tElement and tAttrs (described in the compile function api below) and returns a string value representing the template.


    function resolveTemplate(tElement, tAttrs) {
    
    }
    
    angular.module('MyApp').directive('maybeLink', function() {
      return {
        //...
        template: resolveTemplate,
        //...
      }; 
    });
    

提交回复
热议问题