当文本输入包含特定值时,我想显示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