參考:blog.csdn.net/kuangshp128…javascript
set
與get
方法 :父組件傳遞數據到子組件,子組件接受數據,對其接收的數據進行處理再顯示// 父組件 ts
data:string = "parent"; // 傳遞一個parent給子組件
// 父組件 html
<app-comdemo01 [input]="data"></app-comdemo01> 複製代碼
//子組件ts文件
export class Comdemo01Component implements OnInit {
_input: string;
@Input()
public set input(v: string) {
this._input = v.toUpperCase(); //轉換大寫輸出
}
public get input(): string {
return this._input;
}
constructor() {
}
ngOnInit() {
}
}
//子組件html代碼
I am fron {{input}}
複製代碼