I have an Angular2 Project (IntelliJ IDEA) in witch I use two-way-binding according to this example:
child.component.ts:
counterValue = 0;
@Output() counterChange = new EventEmitter();
@Input()
get counter() {
return this.counterValue;
}
set counter(val) {
this.counterValue = val;
this.counterChange.emit(this.counterValue);
}
decrement() {
this.counter--;
}
increment() {
this.counter++;
}
child.component.html:
<button (click)="decrement()">-</button>
<span>{{counter}}</span>
<button (click)="increment()">+</button>
parent.component.html:
<child-component [(counter)]="co"></child-component>
co: {{co}}
parent.component.ts:
co = 4;
The code works as expected - unless I change some variable names (both ways: using refactor aswell as manually - looking up all references).
I can change the name of counterValue
(even change the variable type through the whole code) but as soon as either refactoring counterChange
(2 occurences, as far as I can tell) or counter(...)
(4 in child.component.ts, 2 in child.component.html, 1 in parent.html) the output-binding to the parent stops working. The child-component however always works as expected; just the co
variable of the parent-component doesn't update anymore.
I went as far as restarting IntelliJ & npm, clearing the caches of IntelliJ and browser: didn't help.
By changing the names back to the ones from the example the output-binding works again.
I'm running out of ideas now and have the terrible feeling of overlooking something fundamental...