Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/AngularPublic.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
ngStyleDirective,
ngSwitchDirective,
ngSwitchWhenDirective,
ngSwitchWhenBindDirective,
ngSwitchDefaultDirective,
ngOptionsDirective,
ngTranscludeDirective,
Expand Down Expand Up @@ -193,6 +194,7 @@ function publishExternalAPI(angular) {
ngStyle: ngStyleDirective,
ngSwitch: ngSwitchDirective,
ngSwitchWhen: ngSwitchWhenDirective,
ngSwitchWhenBind: ngSwitchWhenBindDirective,
ngSwitchDefault: ngSwitchDefaultDirective,
ngOptions: ngOptionsDirective,
ngTransclude: ngTranscludeDirective,
Expand Down
32 changes: 28 additions & 4 deletions src/ng/directive/ngSwitch.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -20,10 +20,11 @@
* attribute is displayed.
*
* <div class="alert alert-info">
* 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="..."`**.
* </div>

* @animations
Expand All @@ -39,16 +40,28 @@
* <ANY ng-switch-default>...</ANY>
* </ANY>
* ```
*
* * ```
* <ANY ng-switch="expression">
* <ANY ng-switch-when-bind="matchVariable1">...</ANY>
* <ANY ng-switch-when-bind="matchVariable2">...</ANY>
* <ANY ng-switch-default>...</ANY>
* </ANY>
* ```
*
*
* @scope
* @priority 1200
* @param {*} ngSwitch|on expression to match against <code>ng-switch-when</code>.
* @param {*} ngSwitch|on expression to match againsts <code>ng-switch-when</code> or
* <code>ng-switch-when-bind</code>.
* 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.
Expand Down Expand Up @@ -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,
Expand Down
8 changes: 6 additions & 2 deletions src/ngResource/resource.js
Original file line number Diff line number Diff line change
Expand Up @@ -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") {
Expand All @@ -606,7 +610,7 @@ angular.module('ngResource', ['ng']).

value.$resolved = true;

response.resource = value;
response.resource = (action.transformResult)? transformedValue : value;

return response;
}, function(response) {
Expand Down