当前位置: 动力学知识库 > 问答 > 编程问答 >

select - AngularJS, Dropdpown set given boolean value as predefined text

问题描述:

I have predefined scope values:

$scope.synchronizationStates =

[

true,

false

];

And i have defined select:

<select class="form-control" data-ng-model="projectDetail.synced" data-ng-options="synced for synchronizationState in projectDetail.synchronized">

</select>

I would like to have for state false display preselected value "NOT_SYNCED" and for true "SYNCED" And also change state value if value is changed by user.

How can I do it please using AngularJs?

Thanks for any advice.

网友答案:

In controller use :

 $scope.synchronizationStates  = [
    {text:'not synced',value:false},
    {text:'synced',value:true},
    ]

and in html

<select ng-model="selected" ng-options="value.value as value.text for value in synchronizationStates"></select>

working plunker here a link!

网友答案:

I think its better for you to use something like this

    ng-options="e as e for e in synchronizationStates "></select>

and maybe make each element in the array an object with string for the name and true or false for the value

分享给朋友:
您可能感兴趣的文章:
随机阅读: