我有那个输入字段
<input [(ngModel)]='inputValue' class="form-control" id="search-box"
(keyup.enter)="submitValue(); false" />
当我粘贴长文本(〜30.000个字符)并按Enter键时,调用我的SubmitValue函数大约需要10秒钟。
app.component.ts
:
import { Component } from '@angular/core';
@Component({
selector: 'my-app',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css']
})
export class AppComponent {
inputValue = '';
result: string = null;
submitValue(): void {
this.result = this.inputValue.trim();
}
}
app.component.html
:
<p>
Add long text and hit [enter] to see delay magic happen :)
</p>
<input [(ngModel)]='inputValue' class="form-control" id="search-box"
(keyup.enter)="submitValue(); false" />
<div>
Result: {{result}}
</div>
也有StackBlitz https://stackblitz.com/edit/angular-pagraj