【发布时间】:2017-01-31 18:57:27
【问题描述】:
我是 Angular2 的新手,我想在单击关闭图标后隐藏父元素。以下是我的代码:
@Component({
selector: 'add-search',
template: `
<input type='text' #newHero
(keyup.enter)="addHero(newHero.value)"
(blur)="addHero(newHero.value); newHero.value='' ">
<button (click)=addHero(newHero.value)>Add</button>
<div>
<div [hidden]="hideElement" style="margin-right:2px" *ngFor="let hero of heroes" class="label label-primary">{{hero}}<span (click)="toggleElement()" style='cursor:pointer; display:inline-block; padding:1px 2px;'><i class="fa fa-times" aria-hidden="true" style="font-size:10px;"></i></span>
</div>
</div>
`
})
export class AddSearchComponent {
heroes = Array<string>();
addHero(newHero: string) {
if (newHero) {
this.heroes.push(newHero);
}
}
private hideElement: boolean = false;
toggleElement() {
if (this.hideElement) {
this.hideElement = false;
else
this.hideElement = true;
}
}
}
隐藏在代码中不起作用。我们可以用简单的方式来做吗?或者最好的方法是什么?
【问题讨论】:
标签: angular typescript1.8