【发布时间】:2018-05-05 13:47:43
【问题描述】:
你能告诉我如何制作输入字段属性的getter和setter吗? 我试过这样
import { Component } from '@angular/core';
@Component({
selector: 'my-app',
templateUrl: './app.component.html',
styleUrls: [ './app.component.css' ]
})
export class AppComponent {
private _keyValue: string;
get KeyValue(): string{
return this._keyValue;
}
set KeyValue(value: string){
console.log('====')
this._keyValue = value;
}
name = 'Angular 6';
}
当我在输入字段中输入时,我的console 没有打印出来,为什么?
这是我的代码
https://stackblitz.com/edit/angular-vnvv6b?file=src%2Fapp%2Fapp.component.ts
【问题讨论】:
-
这可能对您有些价值:angular.io/guide/…
-
你没有使用你创建的setter,你直接绑定到_keyValue
-
我将如何使用?
标签: javascript angular