Last active
August 29, 2015 14:01
-
-
Save Xanir/bb1e5460203ad9e568cc to your computer and use it in GitHub Desktop.
no-bind directive
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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