angular select element

娄嘉石
2023-12-01

1. use obj, the html code like <option value="a1">aaa</option> <option value="b1>bbb</option>

<select style="width:200px;" name="testSelect" id="testSelect"  required ng-model="testSelect" ng-options=" value for (value,key)  in obj " ></select>

$scope.obj={"aaa":"a1","bbb":"b1","ccc":"c1"};

$scope.testSelect="a1";// default value

 

2. use array, but the optoin's value always array's index,i.e. <option value="0" >aaa</option> <option value="1" >bbb</option>

<select style="width:200px;" name="obj"  required ng-model="test" ng-options=" obj.key as obj.value for obj  in objs " >

$scope.objs=[{key:"aaa",value:"a1"},{key:"bbb",value:"b1"}];

 

<select style="width:200px;" name="obj"  required ng-model="test" ng-options=" obj for obj  in objs " >

$scope.objs=['a1','b1','c1'];

 

 类似资料:

相关阅读

相关文章

相关问答