在我的有角项目中,有搜索输入框。单击锚标记时,在这里我想获取ID。我将尝试将click功能放置到锚定标记中,但是没有用。你能帮助我吗。
Angular 7 CLI
<div class="form-group">
<div class="search">
<div class="input">
<label for="exampleInputEmail1">Select Pharamacy</label>
<input name="search" [(ngModel)]="searchText" autocomplete="off" class="form-control input-sm">
<ul class="results">
<li *ngFor="let data of pharmacyData | filterService : searchText; let i = index">
<a (click)="selectedPharmacy(data.pharmacyId)"> {{data.pharmacyName}} </a>
</li>
</ul>
</div>
</div>
</div>
import { Component, OnInit } from '@angular/core';
import { ServerService } from 'src/app/server.service';
@Component({
selector: 'app-admin-add-pharmacy',
templateUrl: './admin-add-pharmacy.component.html',
styleUrls: ['./admin-add-pharmacy.component.css']
})
export class AdminAddPharmacyComponent implements OnInit {
pharmacyData : any;
constructor(private serverService : ServerService) { }
ngOnInit() {
this.serverService.getAllPharmacyData().subscribe(
(response:Response)=>{
this.pharmacyData = response;
console.log(this.pharmacyData);
}
);
}
selectedPharmacy(pharmacyId:any){
console.log(pharmacyId);
}
}
(2) [{…}, {…}]
0: {pharmacyId: 27, pharmacyName: "Medi"}
1: {pharmacyId: 28, pharmacyName: "Medi 2"}
length: 2
__proto__: Array(0)