【问题标题】:How to set angular (Select all ) in side the dropdown如何在下拉菜单中设置角度(全选)
【发布时间】:2019-01-07 11:18:39
【问题描述】:

我正在尝试在我的 Angular 应用程序中开发一个下拉菜单。下拉列表是商店清单。当我选择一家商店时,它将显示或(显示)商店中的内容。所以在这里我想要下拉列表中的商店列表中的一个新项目(项目是所有商店)......就像 这个

这里的数据(购物清单)来自数据库(带有 web api 的角度)

这是我的 Ts 代码

 ngOnInit() {

            this.Service.FetchPopulateOutlets().subscribe(outletsData => this.outletDetails = outletsData,
                error => {


 console.error(error);
                this.statusMessage = "Problem with the service.Please try again after sometime";
            });
    onSelect(shopid: number) {
    this.Service.FetchItemDetails(shopid, 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>

【问题讨论】:

    标签: angular typescript angular2-template angular2-forms angular2-services


    【解决方案1】:
    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";
        });
        onSelect(shopid: number) {
            if (shopId == 0) {
                "Insert your logic here"
            }
            this.Service.FetchItemDetails(shopid, this.pageIndex).subscribe(itemsData => this.itemdetails = itemsData,
                error => {
                    console.error(error);
                    this.statusMessage = "Problem with the service.Please try again after sometime";
                });
        }
    

    【讨论】:

    • 这只是它应该如何工作的想法,你可以粘贴你得到的错误。也许我们可以为您找到可行的解决方案。
    • 让 allShops = { ShopName:'All', ShopID:'0' } this.outletDetails.push(allShops); this.outletDetails.concat(outletsData) 将这部分代码用大括号括起来
    猜你喜欢
    • 2019-08-03
    • 1970-01-01
    • 1970-01-01
    • 2019-03-15
    • 1970-01-01
    • 2019-04-15
    • 1970-01-01
    • 1970-01-01
    • 2020-10-13
    相关资源
    最近更新 更多