0

I am curious if there is a way to disable a filter once its been applied.

for instance:

<h3 class="mention" ng-bind-html="mention | getPlace" place-directive >&nbsp;<span>@</span>{{mention}}</h3>

filter:

hungryApp.filter('getPlace', function($stateParams) {
  return function(place) {
      return '<a>' + '@' + place.placeinfo.placename + '</a>';
  }
});

Once the element is rendered, is there an angular way for that filter to not effect the elements it has already filtered?

I was able to come up with a dirty solution of writing a directive that basically replaces the element with a cloned copy, but definitely not the cleanest solution.

Thanks for any suggestion.

2 Answers 2

1

Answer is accepted but actually not good. As in Angular 1.4 one time binding was introduced:

{{::mention | getPlace}}
Sign up to request clarification or add additional context in comments.

1 Comment

very cool, thanks for the info, thats exactly what i was looking for. And yeh it's definitely a cleaner solution. In my case it would be <h3 class="mention" ng-bind-html="::mention | getPlace">&nbsp;<span>@</span>{{mention}}</h3>
1

Accept a boolean parameter in your filter, and make it return the input, untouched, if the boolean is true (or false). Then pass a boolean variable as argument to your filter, and toggle it to change the behavior of the filter:

hungryApp.filter('getPlace', function($stateParams) {
  return function(place, ignore) {
      if (ignore) {
          return place;
      }
      else {
          return '<a>' + '@' + place.placeinfo.placename + '</a>';
      }
  };
});

In the controller:

$scope.placeFilteringIgnored = false;

$scope.togglePlaceFiltering = function() {
    $scope.placeFilteringIgnored = !$scope.placeFilteringIgnored;
}

And in the view:

<h3 class="mention" ng-bind-html="mention | getPlace:placeFilteringIgnored"></h3>

<button ng-click="togglePlaceFiltering()">Toggle place filtering</button>

1 Comment

thanks for that, that gets me in the right direction.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.