寻找ng-model的替代方案

时间:2016-06-27 09:26:35

标签: javascript angularjs angular-ngmodel

我在textarea上应用ng-model,但它在ie 11中显示错误。我的代码如下。




 < div ng-隐藏= “DoctorDashboardCtrl.showEducation” >
 < textarea placeholder =“2000 Characters Free flow text”width =“832px”height =“100px”class =“form-control”ng-model =“DoctorDashboardCtrl.otherdetails.education”>
 <! -  {{DoctorDashboardCtrl.otherdetails.education}}  - > 
 < / textarea>
< / div>
  




在ie11中将错误视为无效参数后。我将代码更改为




 < div ng-hide =“DoctorDashboardCtrl.showEducation”>
 < textarea placeholder =“2000个字符自由流文本”width =“832px”height =“100px”class =“form-control”ng-bind =“DoctorDashboardCtrl.otherdetails.education”> 
 {{DoctorDashboardCtrl.otherdetails.education}}
 < / textarea>
< / div>
  




但现在,在我打印保存按钮后,我打印的值DoctorDashboardCtrl.otherdetails.education,它没有得到更新,而是显示旧值。有没有其他解决方案或我是否必须处理永远存在的错误?




1 个答案:

答案 0 :(得分:0)

@Gaurav:在代码中添加一个监视器,以便获得更新值

`$scope.$watch(
            function(){
                return $scope.otherdetails.education;
            },
            function(newValue, oldValue){
                if(newValue && newValue != oldValue) {
                    $scope.otherdetails.education = newValue;
                }
            },
            true
        );`

并在控制器启动时分配空数组和字符串:

$scope.otherdetails = []; $scope.otherdetails.education = "";