javascript - Decorating directive with unnamed link function -
how can 1 derocate directive if link function not named. more want decorate select-ui directive. how directive defined:
.directive('uiselect', function() { return { restrict: 'ea', scope: true, compile: function(telement, tattrs) { //some code return function(scope, element, attrs, ctrls){ //some code here //how extend this? } } } }); this how tried, it's giving me error cannot read property 'apply' of undefined, because link function not named in directive :
.decorator('uiselectdirective', function($delegate, restangular){ var directive; directive = $delegate[0]; console.log(directive, $delegate); directive.scope = { endpoint: '=', items: '=', parameters: '=' }; directive.compile = function() { return function($scope, element, attrs){ directive.link.apply(this, arguments); // custom code here } }; return $delegate; }); edit
i tried suggested approach, i'm running issues.
.decorator('uiselectdirective', function($delegate, restangular){ var directive; directive = $delegate[0]; directive.scope = { endpoint: '=', items: '=', parameters: '=' }; directive.compile = function(originalcompile) { var args = arguments; return function($scope, element, attrs){ console.log($scope); // here returning element instead of scope? return originalcompile.apply(this, args); } }(directive.compile); return $delegate; }); instead of $scope i'm getting element variable ([div.ui-select-container.ui-select-bootstrap.dropdown]). have error saying tattrs not defined, parameter in main compule function. i'm guessing apply isn't passing arguments function somehow...
do extend compile function:
directive.compile = function(originalcompile) { return function() { var oldlink = originalcompile.apply(this, arguments); return function($scope, element, attrs) { // custom code link here return oldlink.apply(this, arguments) } } }(directive.compile);
Comments
Post a Comment