gpt4 book ai didi

html - Angularjs 为对象选择 ng-model 绑定(bind)

转载 作者:行者123 更新时间:2023-11-28 05:24:10 25 4
gpt4 key购买 nike

我想选择对象数组。 example但不知何故,我无法访问所选对象的属性。

js---

 $scope.test1={};
$scope.test = [{'name':'test1'},{'name':'test2'},{'name':'test3'}];

html--

<select style="width:100px;height:25px;" ng-model="test1">
<option ng-repeat="attribute in test" value="{{attribute}}">{{attribute['name']}}</option>
</select>
{{test1}}
{{test1.name}}

这里,test1.name 为空。

最佳答案

ngOpions 做这样。它比ng-repeat提供了适当的控制

<select style="width:100px;height:25px;" ng-model="test1"  
ng-options="attribute.name for attribute in test">

这是 Plunker

关于html - Angularjs 为对象选择 ng-model 绑定(bind),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34899017/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com