Angularjs 为angular select from json设置默认值
Iam无法设置默认值以使用角度选择Angularjs 为angular select from json设置默认值,angularjs,Angularjs,Iam无法设置默认值以使用角度选择 <span ng-init="key = viewChecklist.type"> <select ng-model="key" ng-options="key as value for (key, value) in checklist_type"/> </span> 这需要与查看清单的类型相匹配 $scope.viewChecklist = { id: 1, checklist_name: "Test",
<span ng-init="key = viewChecklist.type">
<select ng-model="key" ng-options="key as value for (key, value) in checklist_type"/>
</span>
这需要与查看清单的类型相匹配
$scope.viewChecklist = {
id: 1,
checklist_name: "Test",
type: "2"
}
据我所知,您无法在下拉列表中设置默认的选定项。您可以使用ng init,如下所示:
<select ng-model="key" ng-options="key as value for (key, value) in checklist_type" ng-init="key='key[0]'"/>
这是最新的小提琴:你有什么问题?它工作正常!!奇怪的是,你使用的angular的哪个版本对我有效?我发现的问题是键值必须是字符串而不是整数。一旦将其更改为字符串,它就有效了。谢谢所有:)谢谢它工作了,只需将键值更改为字符串
<select ng-model="key" ng-options="key as value for (key, value) in checklist_type" ng-init="key='key[0]'"/>
$scope.selectedName = $scope.names[1];