amh*_*hev 2 javascript observable rxjs typescript angular
我想从服务中获取输入的最大长度(进行 http 调用以获取值)。
有没有办法只调用一次服务?
<input type="text" [attr.maxLength]="getMaxLength()/>
Run Code Online (Sandbox Code Playgroud)
将 maxLength 属性值设置为在构造函数或 ngOnInit 中设置的类属性将使其不再调用服务
HTML:
<input type="text" [maxLength]="maxLength"/>
Run Code Online (Sandbox Code Playgroud)
打字稿
maxLength: number;
.....
constructor(private myService: MyService){
this.maxLength = this.myService.getMaxLength();
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
12778 次 |
| 最近记录: |