【发布时间】:2018-08-01 18:22:13
【问题描述】:
我正在尝试在我的 Angular 应用程序中开发两个下拉菜单。第一个是shop list,另一个是godown list。当我选择一家商店时,它会在数据上显示它。但是当我选择 Godown 时,它不会更改数据。这里我有两个下拉框。
我认为我的问题出在我的打字稿文件(Onselect)中,因为这里我有 2 个下拉菜单(在 html 中我使用 2 个 Onselect 函数,但在我的 ts 文件中只有一个函数)。 我只是 Angular 的初学者,所以对于这种方法的缺点,我将不胜感激:
ngOnInit() {
this.Service.FetchPopulateOutlets().subscribe(outletsData => {
let allShops = {
ShopName: 'All',
ShopID: 0
}
this.outletDetails = [allShops, ...outletsData]
}, error => {
console.error(error);
this.statusMessage = "Problem with the service.Please try again after sometime";
});
{
this._enqService.FetchGodownPopulateOutlets().subscribe(GodownsData =>
{
let allGodowns = {
GodownName: 'All',
GodownId: 0
}
this.GodownDetails = [allGodowns, ...GodownsData]
},
error => {
console.error(error);
this.statusMessage = "Problem with the service.Please try again after sometime";
});
onSelect(shopid: number, godownid: number) {
this._loginService.selectedshopid = shopid;
this._loginService.selectedgodownid = godownid;
}
this._enqService.FetchItemDetails(shopid,godownid, this.pageIndex).subscribe(itemsData => this.itemdetails = itemsData,
error => {
console.error(error);
this.statusMessage = "Problem with the service.Please try again after sometime";
});
方法
but if i create a separate method for the second dropdown:how to showing data for
this method?
( this._enqService.FetchItemDetails(shopid,godownid, this.pageIndex).subscribe(itemsData => this.itemdetails = itemsData,
error => {
console.error(error);
this.statusMessage = "Problem with the service.Please try again after sometime";)
HTML 文件:
<span>
<select class="formcontrol" name="outletDetail" (change)="onSelect($event.target.value)">
<option value="0" disabled>Select a Shop</option>
<option *ngFor="let outletDetail of outletDetails" value={{outletDetail.ShopID}}>{{outletDetail.ShopName}}</option>
</select>
</span>
<span>
<select class="formcontrol" name="godowndata" (change)="onSelect($event.target.value)">
<option value="0" disabled>Select a Godown</option>
<option *ngFor="let godowndata of GodownDetails" value={{godowndata.GodownId}}>{{godowndata.GodownName}}</option>
</select>
</span>
【问题讨论】:
标签: angular typescript angularjs-directive angular2-forms angular4-httpclient