2016-04-05 38 views
1

我在IE 9/10上面臨奇怪的問題。雙向綁定適用於除了下拉菜單之外的所有html元素。 下拉列表中的值不會被選中。在Angular 2中的IE雙向下拉綁定問題

以下是示例代碼。

HTML

<select [(ngModel)]="model.city" id="city"> 
    <option value="Lahore">Lahore</option> 
    <option value="Karachi">Karachi</option> 
</select> 

TS(Angular2)

this.model.city="Karachi"; 

雙向結合在IE上述條件不能工作。

我已經包含了IE所需的所有墊片,但仍然沒有被選中。

<script src="node_modules/es6-shim/es6-shim.min.js"></script> 
<script src="node_modules/angular2/es6/dev/src/testing/shims_for_IE.js"></script> 
<script src="node_modules/angular2/bundles/angular2-polyfills.js"></script> 

回答

0

HTML

<select class="classic" [(ngModel)]="city" id="selectoption"> 
      <option *ngFor="#city of cityValues">{{city}}</option> 
    </select> 

TS(Angular2)

public cityValues:Array<any>; 
    public city:any 

    //Add below line in constructor 

    this.cityValues=["Lahore","Karachi"]; 

//get the selected value using javascript 

var getSelectedId= document.getElementById('selectoption'); 
var getSelectedValue=getSelectedId.options[getSelectedId.selectedIndex].text; 
this.city=getSelectedValue; 

*注:以上JS當你type.It沾到運行時間值顯示代碼錯誤。