當文本輸入包含特定值時,我想顯示div。向ng鍵添加條件
對於我的模板,我有:
<input type="text" id="jobTitle"
(click)="autoCompleteClick()"
(keypress)="autoCompleteKeypress()" name="autocomplete"
placeholder="Job Title" value="" >
我的想法是按鍵將運行autoCompleteKeyPress功能看起來像這樣:
autoCompleteKeypress() {
if (this.jobTitle == 'bar' || this.jobTitle == 'Bar'){
alert('BOO!');
}
}
目前我只是用一個測試警惕讓它工作。
我的全成分爲:
import { Component } from '@angular/core';
import { Input } from '@angular/core';
@Component({
selector: 'sign-up',
templateUrl: './sign-up.component.html',
styleUrls: ['../variables.less', './sign-up.component.less']
})
export class SignUpComponent {
imgPath = 'assets/images/';
//acInput = document.getElementById('jobTitle');
@Input() jobTitle : string;
autoCompleteKeypress() {
if (this.jobTitle == 'bar' || this.jobTitle == 'Bar'){
alert('BOO!');
}
}
很新的Angular2和打字稿一般,所以任何想法表示讚賞。謝謝!
在js上添加一個運行示例小提琴,plunker,jsbin或你的替代品,所以其他人不必複製粘貼你的代碼。 – NikosKeyz
你想顯示div而用戶在文本框中輸入一定的時間嗎? – CharanRoot