Skip to content

Instantly share code, notes, and snippets.

@Xanir Xanir/noBind
Last active Aug 29, 2015

Embed
What would you like to do?
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
You can’t perform that action at this time.