Angular ng-options remove blank option and select the first option only

后端 未结 2 1864
我寻月下人不归
我寻月下人不归 2021-01-14 05:44

I am using AngularJS to populate my select options content dynamically from an array of objects in my controller. My objects has a property named userProfileName

2条回答
  •  醉酒成梦
    2021-01-14 06:17

    Do this :)

    In your controller :

     function myCtrl ($scope) {
       $scope.userProfiles = [
         {id: 10, name: 'Carton'},
         {id: 27, name: 'Bernard'},
         {id: 39, name: 'Julie'},
      ];
    
       $scope.selectedUserProfile= $scope.userProfiles[0]; // Set by default the   value "carton"
      };
    

    In your page :

          
    

    CodePen: http://codepen.io/anon/pen/qdOGVB

提交回复
热议问题