我有一個使用下面的init方法的typecript控制器。我能夠在消息結果 中獲得我想要的所有數據,這很好。使用angularjs將數據綁定到下拉列表
init() {
this.accountLocationService.getAccountLocationCollection(this.customerNumber)
.success(messageresult => {
this.acctLocationCollection = messageresult;
//alert(this.acctLocationCollection.accountlocation[0].aliasName);
})
.error(error => {
alert(error);
});
}
的acctLocationCollection可以有兩個或多個對象,我需要的 的aliasname的所有值綁定在下面一個下拉。 我該如何實現這一目標?這是我的第一個AngularJs項目。
<div id="acctDetail">
<p>Select an Account:</p>
<div class="selectAccount">
<select class="selAccounts" name="DeliverToCustomerNumber" ng-change="" id="DeliverToCustomerNumber"
ng-options="ac for ac in alc.acctLocationCollection.aliasName">
</select>
</div>
<div id="address">
<dl>
<dd class="acctName">{{alc.acctLocationCollection.DeliverToCompanyName}}</dd>
<dd class="acctNo">{{alc.acctLocationCollection.DeliverToCustomerNumber}}</dd>
</dl>
</div>
</div>
數據看起來像這樣的console.log
object
accountlocation:Array[2]
0:object
aliasName:"1234"
deliverToCustomerNumber: "25235"
1:object
aliasName:"2345"
deliverToCustomerNumber: "23523"
只是注意 - 由於您使用的打字稿,你並不需要一個'的init() '功能。您可以簡單地使用TypeScript構造函數。 (除非你已經從你的構造函數中調用'init()') –
@BenBeck更好的是,從Angular 1.5.x開始,你可以使用'$ onInit(){}'withTypeScript,然後你甚至沒有從你的構造函數中調用它。當模塊實例化時它會自動啓動。 – Lex