diff --git a/src/AngularPublic.js b/src/AngularPublic.js index d608407f0ba7..6d9ba8fbba2f 100644 --- a/src/AngularPublic.js +++ b/src/AngularPublic.js @@ -35,6 +35,7 @@ ngStyleDirective, ngSwitchDirective, ngSwitchWhenDirective, + ngSwitchWhenBindDirective, ngSwitchDefaultDirective, ngOptionsDirective, ngTranscludeDirective, @@ -193,6 +194,7 @@ function publishExternalAPI(angular) { ngStyle: ngStyleDirective, ngSwitch: ngSwitchDirective, ngSwitchWhen: ngSwitchWhenDirective, + ngSwitchWhenBind: ngSwitchWhenBindDirective, ngSwitchDefault: ngSwitchDefaultDirective, ngOptions: ngOptionsDirective, ngTransclude: ngTranscludeDirective, diff --git a/src/ng/directive/ngSwitch.js b/src/ng/directive/ngSwitch.js index 79155f433af5..65440fa335d4 100644 --- a/src/ng/directive/ngSwitch.js +++ b/src/ng/directive/ngSwitch.js @@ -7,8 +7,8 @@ * * @description * The `ngSwitch` directive is used to conditionally swap DOM structure on your template based on a scope expression. - * Elements within `ngSwitch` but without `ngSwitchWhen` or `ngSwitchDefault` directives will be preserved at the location - * as specified in the template. + * Elements within `ngSwitch` but without `ngSwitchWhen` or `ngSwitchWhenBind` or `ngSwitchDefault` directives will be + * preserved at the location as specified in the template. * * The directive itself works similar to ngInclude, however, instead of downloading template code (or loading it * from the template cache), `ngSwitch` simply chooses one of the nested elements and makes it visible based on which element @@ -20,10 +20,11 @@ * attribute is displayed. * *
- * Be aware that the attribute values to match against cannot be expressions. They are interpreted + * Be aware that the attribute values from ng-switch-when to match against cannot be expressions. They are interpreted * as literal string values to match against. * For example, **`ng-switch-when="someVal"`** will match against the string `"someVal"` not against the * value of the expression `$scope.someVal`. + * For cases that need a value to be evaluated you can use **`ng-switch-when-bind="..."`**. *
* @animations @@ -39,16 +40,28 @@ * ... * * ``` + * + * * ``` + * + * ... + * ... + * ... + * + * ``` * * * @scope * @priority 1200 - * @param {*} ngSwitch|on expression to match against ng-switch-when. + * @param {*} ngSwitch|on expression to match againsts ng-switch-when or + * ng-switch-when-bind. * On child elements add: * * * `ngSwitchWhen`: the case statement to match against. If match then this * case will be displayed. If the same match appears multiple times, all the * elements will be displayed. + * * * `ngSwitchWhenBind`: the bindable case statement to match against. If match + * then this case will be displayed. If the same match appears multiple times, + * all the elements will be displayed. * * `ngSwitchDefault`: the default case when no other case match. If there * are multiple default cases, all of them will be displayed when no other * case match. @@ -193,6 +206,17 @@ var ngSwitchWhenDirective = ngDirective({ } }); +var ngSwitchWhenBindDirective = ngDirective({ + transclude: 'element', + priority: 1200, + require: '^ngSwitch', + multiElement: true, + link: function (scope, element, attrs, ctrl, $transclude) { + ctrl.cases['!' + scope.$eval(attrs.ngSwitchWhenBind)] = (ctrl.cases['!' + scope.$eval(attrs.ngSwitchWhenBind)] || []); + ctrl.cases['!' + scope.$eval(attrs.ngSwitchWhenBind)].push({ transclude: $transclude, element: element }); + } +}); + var ngSwitchDefaultDirective = ngDirective({ transclude: 'element', priority: 1200, diff --git a/src/ngResource/resource.js b/src/ngResource/resource.js index 4cee239f891c..e2323e9226ec 100644 --- a/src/ngResource/resource.js +++ b/src/ngResource/resource.js @@ -585,8 +585,12 @@ angular.module('ngResource', ['ng']). 'contain an {1} but got an {2} (Request: {3} {4})', name, action.isArray ? 'array' : 'object', angular.isArray(data) ? 'array' : 'object', httpConfig.method, httpConfig.url); } + var transformedValue = null; // jshint +W018 - if (action.isArray) { + //If user provide transformResult function, returns user needed results + if(action.transformResult){ + transformedValue = action.transformResult(data); + } else if (action.isArray) { value.length = 0; forEach(data, function(item) { if (typeof item === "object") { @@ -606,7 +610,7 @@ angular.module('ngResource', ['ng']). value.$resolved = true; - response.resource = value; + response.resource = (action.transformResult)? transformedValue : value; return response; }, function(response) {