I tried to put together a more in-depth demo what I am trying to do:

http://bjam.in/ng2-fail-ng-model

It works with the setTimeout(), but is very clearly sub-optimal. Any help 
is much appreciated. Super frustrating.




On Sunday, January 31, 2016 at 7:16:05 AM UTC-5, Ben Nadel wrote:
>
> Looking through all the existing valueAccessors examples in the AngularJS 
> source code doesn't help because all of them simply update existing DOM 
> elements. As such, the writeValue() method never updates anything that is 
> part of dirty-checking.
>
> I need to update the value of an AngularJS component, based on the 
> writeValue().
>
>
>
> On Sunday, January 31, 2016 at 6:54:54 AM UTC-5, Ben Nadel wrote:
>>
>> I am trying to understand how to create custom valueAccessor 
>> implementations to bind [ngModel] to an existing Widget directive in order 
>> to give it two-way data binding. So, imagine that I have:
>>
>> Widget
>> inputs: [ "value" ] ---> Sets the selected value of the widget.
>> outputs: [ "select" ] ---> Emits event when value *should be selected* 
>> (ie, doesn't change it internally).
>>
>> Ok, now I'm trying to create a valueAccessor that selects on 
>> "widget[ngModel]"... such that 
>>
>> <widget [(ngModel)]="someValue" />
>>
>> ... will match TWO directives - the "Widget component" (which knows 
>> nothing about ngModel) and the "accessor directive."
>>
>> So far so good. Until I implement the *writeValue()* method:
>>
>> function writeValue( newValue ) {
>> widget.value = newValue;
>> }
>>
>> Here, Angular is throwing the error:
>>
>> Expression 'value in AppController@4:8' has changed after it was checked. 
>> Previous value: 'false'. Current value: 'true' in [value in 
>> AppController@4:8]
>>
>> If I wrap the "widget.value = newValue;" in a setTimeout(), the error 
>> goes away. But, I don't believe this is a *fix*. I think I am just missing 
>> something fundamental about change detection. Or valueAccessors. 
>>
>> It almost as if the fact that both directives match on the same Node, one 
>> directive cannot alter the other's inputs. But, as they are different 
>> directives, 
>>
>> Thanks!
>>
>

-- 
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 https://groups.google.com/group/angular.
For more options, visit https://groups.google.com/d/optout.

Reply via email to