Today I learned how to set the default value of the ng-options drop-down data in angular.Leave a note

Directly on the code

                  ng-options="teacher.username for teacher in teacherlist" required>
                <option value="">select teacher</option>


   //data is the id of the course
   $scope.edit=function (data) {
      //Get course object by course id
      courseservice.getbycourseid (data) .then (function (result) {
        //Default value setting
        //First get the teacher object by the teacher id in the course
        courseservice.getteacherbyteacherid (result.data.teacherid) .then (function (result) {
         //$scope.teacherlist is a list of all teachers
          for (i=0;i<$scope.teacherlist.length;i ++) {
            //If the id of the teacher of the current course is equal to the id of the teacher currently traversed, give the object of the teacher currently traversed to ng-model="editcourse.teachername"
            if (result.data.userid == $scope.teacherlist [i] .userid) {
              $scope.editcourse.teachername=$scope.teacherlist [i];
        angular.element ("#edit"). modal ({


  • Previous WebUploader + SpringMVC to implement file upload function
  • Next Java uses DFA algorithm to implement sensitive word filtering
  • Trends