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梦
过去多啦不再A梦 2017-05-15 16:56:59
0
2
553
 <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]
过去多啦不再A梦
过去多啦不再A梦

reply all(2)
仅有的幸福

That’s because it’s executing repeat 的时候 ng-model 尚未有值 ,你可以发现空白的那个option中会有一个 value="?"
给一个初始化话的值就好了
$scope.currenttype=$scope.roles[0];
That’s it

Peter_Zhu

model is not initialized

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template