In a component how to databind two-way for the following example:
I want the button's text to toggle automatically when I am setting or unsetting dataitem.isSelected
in the respective methods
Here is the code of channelstab.component.ts
@Component({
selector: 'channels-tab',
template: `
<ListView [items]="channels$ | async" class="list-group">
<ng-template let-dataitem="item">
<Button [text]="dataitem.isSelected?'UnFollow':'follow'" (tap)="dataitem.isSelected?unfollow(dataitem):follow(dataitem)"></Button>
</ng-template>
</ListView>
`,
changeDetection: ChangeDetectionStrategy.OnPush
})
export class ChannelsTabComponent implements OnInit {
public channels$: Observable<any>;
ngOnInit() {
this.channels$ = <any>this.someService.get('channels');
}
unfollow(dataitem) {
dataitem.isSelected = false;//not working
}
follow(dataitem) {
dataitem.isSelected = true;//not working
}
}