2016-10-17 46 views
0

我有一大堆的地方,我需要NG-显示添加到要隐藏的元素。它可以从代码中的一个位置完成吗?热做NG-显示没有属性

所以不是这个模板:

<tr my-row ng-show="$ctrl.model.toShow()"></tr> 

它应该是:

<tr my-row ></tr> 

,然后在指令:

function myRow(){ 
    return { 
     restrict: 'A', 
     templateUrl: 'my-row.html', 
     .. 
     link = function(scope,el,attrs){ 
      scope.$watch('modle.toShow', function(){ 
        //something here? 
      }) 
     } 

    }; 
} 

回答

1

进行这些更改的链接功能,这会为您的my-row指令添加一个属性ng-show

var app = angular.module('app', []) 
.directive('myRow', function($compile) { 
    return { 
     restrict: 'A', 
     templateUrl: 'my-row.html', 

     link: function (scope, element, attrs) { 
      var attr; 
      element.attr('ng-show', true); 
      var fn = $compile(element); 
      return function(scope){ 
      fn(scope); 
     }; 

     } 
    }; 
}) 

HEre is the plunker

+0

增加了plunker,请检查。 – Sravan

+0

谢谢!!!!!! – user656449