Simply put, I want to two-way bind my Switch component to a boolean in a service
Something like this:
@Component({
selector: 'my-switch',
template: '...'
})
export class Switch {
@Input() state: Boolean
toggle() {
if (this.state) {
this.state = false
} else {
this.state = true
}
}
}
@Injectable()
class export FooService {
theBoolean: Boolean
}
@Component({
selector: 'my-app',
template: '<my-switch [(state)]="_foo.theBoolean"></my-switch>{{ _foo.theBoolean }}'
})
export class App {
constructor(private _foo: FooService) {}
}
So what should happen here is that, when the switch is toggled, the onChanges event in FooService should fire, and vice versa.