Fantastic solution Josh..Thank you.

On Friday, April 5, 2013 12:41:14 AM UTC+5:30, Josh David Miller wrote:
>
> Hello!
>
> Order of execution is the important part here, roughly: compiler -> 
> controller -> link -> interpolation. Until the interpolation is done, there 
> is no value for '@'. That's why your checks didn't work.
>
> That said, while there is no default mechanism for this, you can set up an 
> $observe on interpolated attributes; the $observe will always fire the 
> first time, even if there was no value passed. You can use this to set your 
> default. $observe is very efficient.
>
> attrs.$observe( 'attr1', function(val) {
>   if ( !angular.isDefined( val ) ) {
>     scope.attr1 = 'defaultValue';
>   }
> });
>
> It would be nice to have a mechanism for setting defaults for '@', but it 
> would be syntactically awkward considering defaults don't make sense for 
> '=' and '&'.
>
> Josh
>
>
> On Thu, Apr 4, 2013 at 11:43 AM, Charles Kilbourne <[email protected] 
> <javascript:>> wrote:
>
>> Hey guys,
>>
>> Its all in the title, here is an example of what I mean
>>
>> This would be the isolate scope set in the directive
>> scope:{
>>   attr1:'@',
>>   attr2:'@'
>> }
>>
>> Now if someone wanted to use the directive they could do this
>>
>> <div my-directive attr1="someValue" attr2="otherValue"></div>
>>
>> however the user should have the option to leave out attributes and if so 
>> the controller would be able to detect this and fall back to a default 
>> value, I have tried checking if the variable is undefined but that does not 
>> work. Does anyone know of a way to get this done?
>>
>> Thanks in advance 
>>
>> -- 
>> You received this message because you are subscribed to the Google Groups 
>> "AngularJS" group.
>> To unsubscribe from this group and stop receiving emails from it, send an 
>> email to [email protected] <javascript:>.
>> To post to this group, send email to [email protected] 
>> <javascript:>.
>> Visit this group at http://groups.google.com/group/angular?hl=en-US.
>> For more options, visit https://groups.google.com/groups/opt_out.
>>  
>>  
>>
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"AngularJS" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/angular.
For more options, visit https://groups.google.com/d/optout.

Reply via email to