One way data binding in Angular2

前端 未结 4 1929
情歌与酒
情歌与酒 2020-12-08 08:39

I got the following html


I want the data and columns properties to

4条回答
  •  广开言路
    2020-12-08 09:21

    • if you use [ngModel], [value], {{ param }} etc. you have one-way binding, model to view,
    • if you use (ngModelChange) you have one-way binding, view to model,
    • if you use [(ngModel)] you have two way binding.

    But you are using a sub-component with the input @Input() property and this dances out of the line ;-) The notation is not what it looks like because it's always binded.

    
    

    So if you change the myObj in your sub-component, it will be binded:

    ngOnInit() {
        this.myObj = this.myObj.push(this.newObj);
    }
    

    You could work with a local copy of myObj to prevent binding.

    If you need an update from model you can push it with @Output() as Event:

    
    

提交回复
热议问题