这段代码中有一个错误
<img src="../../../assets/gms-logo.png" alt="logo" routerLink="/overview" alt="website icon">
但当我检查资产文件夹时,gms-logo.png仍在那里,在angular-cli.json中,资产也在那里.路径也是正确的.
Has the program started searching even if the user is still not focused on the input type? How do I fix this?
<input type="text" placeholder="Search" (keyup)="onSearch($event.target.value)"> <div class="suggestion" *ngIf="results.length > 0"> <div *ngFor="let result of results "> <a href="" target="_blank"> {{ result.name }} </a> </div> </div>
以下是我的组件
results: Object; onSearch(name) { this.search .searchEmployee(name) .subscribe( name => this.results = name,//alert(searchName),this.route.navigate(['/information/employees/']),error => alert(error),); }
解决方法
您需要将结果变量初始化为数组.
在您的组件中,添加:
results = [];
另一种选择是更改建议div的* ngIf语句以检查结果是否已定义:
<div class="suggestion" *ngIf="results"> <div *ngFor="let result of results "> <a href="" target="_blank"> {{ result.name }} </a> </div> </div>