Skip to content

Instantly share code, notes, and snippets.

@Xanir
Last active August 29, 2015 14:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Xanir/bb1e5460203ad9e568cc to your computer and use it in GitHub Desktop.
Save Xanir/bb1e5460203ad9e568cc to your computer and use it in GitHub Desktop.
no-bind directive
(function(angular, $) {
var module = angular.module('net.enzey.bindonce', []);
var ctrlBind = function($parse) {
return function($scope) {
$scope.$watch = function(varExpression, func) {
// varExpression.exp is passed as the 'old' value
// so that angular can remove the expression text from an
// element's attributes, such as when using an expression for the class.
func($parse(varExpression)($scope), varExpression.exp);
};
};
};
var linkBind = function($timeout) {
return function(scope, element, attrs) {
element.find('*').removeClass('ng-binding');
$timeout(function() {
scope.$destroy();
}, 0, false);
};
};
module.directive('nzNoBind', function ($parse, $timeout) {
return {
restrict: 'A',
priority: 9999,
scope: true,
controller: ctrlBind($parse),
link: function(scope, element, attrs) {
element.removeClass('ng-scope');
element.removeClass('ng-binding');
linkBind($timeout)(scope, element, attrs);
}
};
});
module.directive('nzNoBindChildren', function ($parse, $timeout) {
return {
restrict: 'A',
priority: -9999,
scope: true,
controller: ctrlBind($parse),
link: linkBind($timeout)
};
});
})(angular, jQuery);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment