首页 > angular中用$watch监视select总是会多出一个空白选项,当第一选择之后那个空白就没了,有人遇到同样情况么

angular中用$watch监视select总是会多出一个空白选项,当第一选择之后那个空白就没了,有人遇到同样情况么

 <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]

那是因为在执行 repeat 的时候 ng-model 尚未有值 ,你可以发现空白的那个option中会有一个 value="?"
给一个初始化话的值就好了
$scope.currenttype=$scope.roles[0];
就好


model没有初始化啦

【热门文章】
【热门文章】