angular的属性绑定

版权声明:.net/web/医疗技术的木子纵横的个人分享 https://blog.csdn.net/muzizongheng/article/details/85246858
[ngModel] 单向绑定, 从model到view
(ngModelChange) 单向绑定, 从view到model,比如click事件, (click)='onClick($event)'
[(ngModel)] 双向绑定

使用ngModel时,最好加上name属性。

例子:
@Component({
  selector: 'exe-app',
  template: `
   <form novalidate #f="ngForm">
      Name: <input type="text" name="username" [(ngModel)]="user.username">
   </form>
   {{ user | json }}
  `,
})
export class AppComponent implements OnInit {
  user: { username: string };

  ngOnInit() {
    this.user = { username: 'Semlinker' };
  }
}



猜你喜欢

转载自blog.csdn.net/muzizongheng/article/details/85246858
今日推荐