我无法在选择列表中设置默认值

时间:2015-03-21 17:17:54

标签: angularjs

我做错了什么?因为我无法在我的选择列表中设置id为= 995的默认选项?

<script>
    var model = {"MeetingPlacesList":[{"Disabled":false,"Group":null,"Selected":false,"Text":"Place 991","Value":"991"},{"Disabled":false,"Group":null,"Selected":false,"Text":"Place 993","Value":"993"},{"Disabled":false,"Group":null,"Selected":false,"Text":"Place 995","Value":"995"}]};


var myApplication = angular.module('MyApplication', []);

    myApplication.controller('MeetingController', function ($scope, $http, $filter) {        
        $scope.MeetingPlacesList = model.MeetingPlacesList;

        $scope.FormData = {};
        $scope.FormData.SelectedMeetingPlaceId = 995; // it doeasn't work
    });
</script>

<select name="SelectedMeetingPlaceId" ng-model="FormData.SelectedMeetingPlaceId" ng-options="place.Value as place.Text for place in MeetingPlacesList"></select>

2 个答案:

答案 0 :(得分:0)

它应该是一个字符串:

$scope.FormData.SelectedMeetingPlaceId = "995";

因为比较是严格平等的。

请参阅fiddle

答案 1 :(得分:0)

它必须是一个字符串。在angularjs中,比较总是严格的。因此995与'995'不同。这就是为什么你没有看到设定值的原因。

$scope.FormData.SelectedMeetingPlaceId = '995';

<强> DEMO