May 21
deco rior [ANGULAR]Initial Value - cool directive - plays nice with Lasso
May 21, 2015; 06:13
deco rior
[ANGULAR]Initial Value - cool directive - plays nice with Lasso
One of the most annoying parts of Angular is that they want ALL the initial setup to be done through an HTTP call. Since in my case the first call is to lasso, this adds another "silly" step to the process, or you have to come up with other way of dealing with initial values (i.e. injecting them).
Using ng-init is "bad" or even worse! This is based on the fact that it is never quite clear when it persists.
I came across a directive (see below)that solves this for initial input values (by compiling them into the scope)
with the following use
<input type="hidden" name="report_id" id="report_id" ng-model="report.report_id" ng-init="100" value="100" initial-value>
This makes all nice with the world! AND keeps you in the Angular police good graces!
-------------------------------------------------------------------
..directive('initialValue', function() {
return{
restrict: 'A',
controller: ['$scope', '$element', '$attrs', '$parse', function($scope, $element, $attrs, $parse){
var getter, setter, val, tag;
tag = $element[0].tagName.toLowerCase();
val = $attrs.initialValue || $element.val();
if(tag === 'input'){
if($element.attr('type') === 'checkbox'){
val = $element[0].checked ? true : undefined;
} else if($element.attr('type') === 'radio'){
val = ($element[0].checked || $element.attr('selected') !== undefined) ? $element.val() : undefined;
}
}
if($attrs.ngModel){
getter = $parse($attrs.ngModel);
setter = getter.assign;
setter($scope, val);
}
}]
}})
#############################################################
This message is sent to you because you are subscribed to
the mailing list Lasso Lasso@lists.lassosoft.com
Official list archives available at http://www.lassotalk.com
To unsubscribe, E-mail to: <Lasso-unsubscribe@lists.lassosoft.com>
Send administrative queries to <Lasso-request@lists.lassosoft.com>
May 21
Jolle Carlestam Re: [ANGULAR]Initial Value - cool directive - plays nice with Lasso
May 21, 2015; 14:19
Jolle Carlestam
Re: [ANGULAR]Initial Value - cool directive - plays nice with Lasso
May 21
deco rior Re: [ANGULAR]Initial Value - cool directive - plays nice with Lasso
May 21, 2015; 06:28
deco rior
Re: [ANGULAR]Initial Value - cool directive - plays nice with Lasso
May 21
deco rior Re: [ANGULAR]Initial Value - cool directive - plays nice with Lasso
May 21, 2015; 06:31
deco rior
Re: [ANGULAR]Initial Value - cool directive - plays nice with Lasso
May 21
Jolle Carlestam Re: [ANGULAR]Initial Value - cool directive - plays nice with Lasso
May 21, 2015; 14:32
Jolle Carlestam
Re: [ANGULAR]Initial Value - cool directive - plays nice with Lasso
May 21
Jolle Carlestam Re: [ANGULAR]Initial Value - cool directive - plays nice with Lasso
May 21, 2015; 15:45
Jolle Carlestam
Re: [ANGULAR]Initial Value - cool directive - plays nice with Lasso
May 21
deco rior Re: [ANGULAR]Initial Value - cool directive - plays nice with Lasso
May 21, 2015; 07:57
deco rior
Re: [ANGULAR]Initial Value - cool directive - plays nice with Lasso
May 21
Jolle Carlestam Re: [ANGULAR]Initial Value - cool directive - plays nice with Lasso
May 21, 2015; 16:32
Jolle Carlestam
Re: [ANGULAR]Initial Value - cool directive - plays nice with Lasso
May 21
deco rior Re: [ANGULAR]Initial Value - cool directive - plays nice with Lasso
May 21, 2015; 16:31
deco rior
Re: [ANGULAR]Initial Value - cool directive - plays nice with Lasso
May 22
Jolle Carlestam Re: [ANGULAR]Initial Value - cool directive - plays nice with Lasso
May 22, 2015; 08:08
Jolle Carlestam
Re: [ANGULAR]Initial Value - cool directive - plays nice with Lasso
May 22
deco rior Re: [ANGULAR]Initial Value - cool directive - plays nice with Lasso
May 22, 2015; 08:47
deco rior
Re: [ANGULAR]Initial Value - cool directive - plays nice with Lasso
May 22
Jolle Carlestam Re: [ANGULAR]Initial Value - cool directive - plays nice with Lasso
May 22, 2015; 16:58
Jolle Carlestam
Re: [ANGULAR]Initial Value - cool directive - plays nice with Lasso
May 22
deco rior Re: [ANGULAR]Initial Value - cool directive - plays nice with Lasso
May 22, 2015; 09:31
deco rior
Re: [ANGULAR]Initial Value - cool directive - plays nice with Lasso