Skip to content

Instantly share code, notes, and snippets.

@darlanalves
Created August 5, 2014 04:25
Show Gist options
  • Save darlanalves/250d1a73849f8bb2a9ee to your computer and use it in GitHub Desktop.
Save darlanalves/250d1a73849f8bb2a9ee to your computer and use it in GitHub Desktop.
A naive implementation of ng-bindonce
angular.module('ng').directive('ngBindonce', function() {
return function bindOnce($scope, $element, $attrs) {
var removeWatcher = $scope.$watch($attrs.ngBindOnce, function(value) {
if (value === undefined) return;
$element.text(value);
removeWatcher();
});
};
});
<!-- ... -->
<div ng-bindonce="some.binding"></div>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment