我有一个使用下面的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