T
T
Trajor2017-03-18 21:57:31
Angular
Trajor, 2017-03-18 21:57:31

How can I make the directive output nothing?

jsfiddle.net/HB7LU/28043 The directive should output nothing
, depending on the condition , even itself. How to do it?)

Answer the question

In order to leave comments, you need to log in

2 answer(s)
M
Mikhail Serenkov, 2017-03-18
@miserenkov

In your html do like this:

<super-puper ng-repeat="x in data" ng-if="x != 3"></super-puper>

S
SergeyBugai, 2017-03-20
@SergeyBugai

You can, as @Mikhail Serenkov wrote, or you can remove the template in the directive, or something like that

myApp.directive('superPuper', function() {
  return {
        restrict: 'E',
        replace: true,
        link: function($scope, element, attrs) {
       		var val = $scope.x;
          if(val !== 3) {
          	//Ничего не выводим!!!
            var li = angular.element('<li>');
            li[0].textContent = val;
            element.append(li);
          }
        	
       }   		
   }
})

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question