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

前端 未结 12 604
被撕碎了的回忆
被撕碎了的回忆 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:47

    Really simple if you do not care about indexing your options with some numeric id.

    1. Declare your $scope var - people array

      $scope.people= ["", "YOU", "ME"];
      
    2. In the DOM of above scope, create object

      
      
    3. In your controller, you set your ng-model "hired".

      $scope.hired = "ME";
      

    Good luck!!! It's really easy!

提交回复
热议问题