标签:hang pre 后缀 core put tor cto owa str
import { Component, OnInit, Output, Input, EventEmitter } from ‘@angular/core‘; @Component({ selector: ‘twoway‘, template: ` <input [(ngModel)]="username"> <p>Hello {{username}}!</p> ` }) export class TwoWayComponent implements OnInit { constructor() { } usernameValue: string; @Output() usernameChange = new EventEmitter(); @Input() get username() { return this.usernameValue; } set username(val) { this.usernameValue = val; this.usernameChange.emit(this.usernameValue); } ngOnInit() { } }
使用时,就可以通过[(username)]=“你的当前熟悉” 进行双向绑定了。属性名 + 后缀 Change是一个约定的固定写法。
标签:hang pre 后缀 core put tor cto owa str
原文地址:http://www.cnblogs.com/sgciviolence/p/6552987.html