我要动态地改变输入占位符的文本。在执行console.log已经提供了更新后的字符串,但接口不更新所以停留在旧的占位符。我怎样才能识别更改界面?
document.getElementById(this.implicKey).setAttribute('placeholder', options[i].implication);
console.log(document.getElementById(this.implicKey).getAttribute('placeholder'));
可以动态改变你的输入占位符这样的
<md-input-container class="demo-full-width">
<input mdInput [(ngModel)]="firstname" placeholder="{{somePlaceholder}}" name="firstname" required>
<md-error>This field is required</md-error>
</md-input-container>
component.ts
somePlaceholder : string = "new value";
现在你可以在任何地方类改变一些占位符值。
我们可以做的是使用属性结合。
在HTML中,使用方括号:
<input formControlName="events" type="text" [placeholder]="newPlaceHolder">
在您的打字稿文件,定义属性:
newPlaceHolder: string = "original place holder";
然后,更改属性值:
newPlaceHolder= "my new place holder";