1

I want to use the following bindOnce directive:

.directive('bindOnce', function() {
    return {
        scope: true,
        link: function( $scope, $element ) {
            setTimeout(function() {
                $scope.$destroy();
                $element.removeClass('ng-binding ng-scope');
            }, 0);
        }
    }
});

If I use this on a simple piece of html like so:

<span class="highlight" data-bind-once> "{{listing.searchTerm}}"</span>

What happens is that there is nothing but the "" being displayed!

I am loading my data using the $http service, I think the bind-once must get removed before I have loaded my data and then it obviously doesn't get bound.

I want to use this in many places in my app, is this a limitation or am I doing this incorrectly?

Neil
  • 7,861
  • 4
  • 53
  • 74

1 Answers1

0

The newer versions of angular have the ability to bind once within them:

<span class="highlight"> "{{ ::listing.searchTerm }}"</span>

Link: https://docs.angularjs.org/guide/expression#one-time-binding

Mathew Berg
  • 28,625
  • 11
  • 69
  • 90
  • I just tried the latest 1.3x version of Angular and this doesn't seem to work for me either. – Neil Nov 10 '14 at 14:01