JSFiddle - React, Tailwind, and code Playground
HTML
<div ng-app="app" ng-controller="test">
<div bind-once>I bind once - {{message}}</div>
<div>I bind - {{message}}</div>
<button ng-click="change()">Change message</button>
</div>
JavaScript
var app = angular.module('app', []);
app.controller('test', function( $scope ) {
$scope.message = 'Hello World';
$scope.change = function() {
$scope.message = 'Hello People';
}
});
app.directive('bindOnce', function() {
return {
scope: true,
link: function( $scope, $element ) {
setTimeout(function() {
$scope.$destroy();
}, 0);
}
}
});