how to use ng-option to set default value of select element

前端 未结 12 645
被撕碎了的回忆
被撕碎了的回忆 2020-11-22 11:07

I\'ve seen the documentation of the Angular select directive here: http://docs.angularjs.org/api/ng.directive:select. I can\'t figure how to set the default value. This is

12条回答
  •  渐次进展
    2020-11-22 11:58

    If your array of objects are complex like:

    $scope.friends = [{ name: John , uuid: 1234}, {name: Joe, uuid, 5678}];
    

    And your current model was set to something like:

    $scope.user.friend = {name:John, uuid: 1234};
    

    It helped to use the track by function on uuid (or any unique field), as long as the ng-model="user.friend" also has a uuid:

    
    

提交回复
热议问题