简体   繁体   English

Angular2 select-option下拉列表在HTML页面加载时动态加载

[英]Angular2 select-option dropdown dynamic loading on HTML page load

I have a HTML page where I am using 2 select - option drop-down I want to fill the second drop-down on the basis of what is selected in the first drop-down. 我有一个HTML页面,我在其中使用2 select-option下拉列表,我想根据第一个下拉列表中的选择来填充第二个下拉列表。

Actually there are 2 drop-downs I have some values in first drop-down on-loading the page for first time one is selected depending on API result, now I want to bind the list to second drop-down based on what is selected in first drop-down. 其实有2个下拉菜单,我在第一次下载页面的第一个下拉菜单中有一些值,这是根据API结果选择的,现在我想根据列表中选择的内容将列表绑定到第二个下拉列表首先下拉。

Can anyone help me in doing that in Angular 2 HTML select-option 谁能帮我在Angular 2 HTML select-option中做到这一点

<td>
    <div>
        <select #selectedHeading (change)="headingChanged($event.target.selectedIndex)" [disabled]='butDisabled'>
            <option *ngFor="let heading of headings" [value]="heading.val" [ngValue]="accountitem" [selected]="accountitem.heading === heading.val" >
               {{heading.val}}
            </option>
        </select>
    </div>
</td>
<td>{{accountitem.rules}}</td>
<td>
    <select #selectedSubHeading [disabled]='butDisabled'>
        <option *ngFor="let subHeading of subHeadings" [value]="subHeading.val">{{subHeading.val}}</option>
    </select>
</td>

change this variable to count++ in ngOnInit() and we will check in inside this method. 将此变量更改为ngOnInit()中的count ++,我们将在此方法中签入。

count:number=0;
    headingChanged(receivePraam){
    if(count){
this.butDisabled=true;
    }
    else{
this.butDisabled=false;
}
    //and here set dropdown2 value.
    }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM