From 8f5d9b6639d4570c54fcf329a2bc61a2a820bf7d Mon Sep 17 00:00:00 2001 From: Hassan Date: Tue, 28 Jul 2015 07:21:35 +0000 Subject: [PATCH 1/3] Add new type of switch item, that accept Variables --- src/ng/directive/ngSwitch.js | 32 ++++++++++++++++++++++++++++---- 1 file changed, 28 insertions(+), 4 deletions(-) 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, From 8e9ba49b17895e04b39072d2bffdde6ad422a312 Mon Sep 17 00:00:00 2001 From: Hassan Date: Tue, 28 Jul 2015 10:10:41 +0000 Subject: [PATCH 2/3] Update AngularPublic.js --- src/AngularPublic.js | 2 ++ 1 file changed, 2 insertions(+) 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, From d5dabe97ae2f24d490c467587ad679dea3457c57 Mon Sep 17 00:00:00 2001 From: Hassan Date: Wed, 6 Apr 2016 13:33:44 +0430 Subject: [PATCH 3/3] Provide 'transformResult' action i use TS files to write my model, it was several days already, that i wanted to append an interface to my model, but it always failed and i was wonder why... asking around, searching a lot... but nothing... Yesterday, i wrote a new module that need to check for input parameter type. i saw what it fails... and again searching through code and topics... so at some point i found angular change my model again... seeing what... i told 'transformResponse' to return an object of type AcDocRow, but after steping through i saw, hey waits, it's again an stringified json :| ... Searching searching searching... -lot of people have same issue, it's not only me... -Angular Resource Pass Object to Http.. and it return the value to angular, angular again modify the object.... -lot of conversion from string to object and vice versa. -no solution... what should i do? well let see through the code... and i add ability to add a new action which modify the actual result. and you can bypass transformResponse too. which seem more complicated. it's all seem to be clean... so i hope it be acceptable by the jury. I also it get updated in new version of angular too... I'm capable of filling the doc, but i'm not a native english talker. so i leave it to your hand. i also create pull request in https://github.com/deadmann/code.angularjs.org --- src/ngResource/resource.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) 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) {