angular.js - When using $watch to monitor select in angular, there will always be an extra blank option. After the first selection, the blank option disappears. Has anyone encountered the same situation?
过去多啦不再A梦
2017-05-15 16:56:59
<select name="" id="" ng-model="currenttype">
<option value="null">---请选择---</option>
<option ng-repeat="r in roles" value={{r.emp_id}}>{{r.emp_name}}</option>
</select>
$scope.currenttype="";
$scope.$watch('currenttype',function(){
alert($scope.currenttype);
})
![图片描述][1]
That’s because it’s executing
repeat
的时候ng-model
尚未有值 ,你可以发现空白的那个option
中会有一个value="?"
给一个初始化话的值就好了
$scope.currenttype=$scope.roles[0];
That’s it
model is not initialized