From ac490c1dcf0470c2eb057bd4b6a6cb55237b8f4b Mon Sep 17 00:00:00 2001 From: Gias Kay Lee Date: Tue, 7 Jan 2014 21:25:46 +0800 Subject: [PATCH] refactor(booleanAttrs, ngSwitch): use link function instead of compile function where appropriate Replace two compile functions that immediately return a post-link function with link function definitions instead. --- src/ng/directive/booleanAttrs.js | 10 ++++------ src/ng/directive/ngSwitch.js | 8 +++----- 2 files changed, 7 insertions(+), 11 deletions(-) diff --git a/src/ng/directive/booleanAttrs.js b/src/ng/directive/booleanAttrs.js index e69058208e47..30e57bdfd5d9 100644 --- a/src/ng/directive/booleanAttrs.js +++ b/src/ng/directive/booleanAttrs.js @@ -336,12 +336,10 @@ forEach(BOOLEAN_ATTR, function(propName, attrName) { ngAttributeAliasDirectives[normalized] = function() { return { priority: 100, - compile: function() { - return function(scope, element, attr) { - scope.$watch(attr[normalized], function ngBooleanAttrWatchAction(value) { - attr.$set(attrName, !!value); - }); - }; + link: function(scope, element, attr) { + scope.$watch(attr[normalized], function ngBooleanAttrWatchAction(value) { + attr.$set(attrName, !!value); + }); } }; }; diff --git a/src/ng/directive/ngSwitch.js b/src/ng/directive/ngSwitch.js index 99832fc8f34c..459669a2054d 100644 --- a/src/ng/directive/ngSwitch.js +++ b/src/ng/directive/ngSwitch.js @@ -168,11 +168,9 @@ var ngSwitchWhenDirective = ngDirective({ transclude: 'element', priority: 800, require: '^ngSwitch', - compile: function(element, attrs) { - return function(scope, element, attr, ctrl, $transclude) { - ctrl.cases['!' + attrs.ngSwitchWhen] = (ctrl.cases['!' + attrs.ngSwitchWhen] || []); - ctrl.cases['!' + attrs.ngSwitchWhen].push({ transclude: $transclude, element: element }); - }; + link: function(scope, element, attrs, ctrl, $transclude) { + ctrl.cases['!' + attrs.ngSwitchWhen] = (ctrl.cases['!' + attrs.ngSwitchWhen] || []); + ctrl.cases['!' + attrs.ngSwitchWhen].push({ transclude: $transclude, element: element }); } });