AngularJs无法查看输入的更新值和设置ng-invalid

时间:2014-09-23 12:46:46

标签: javascript jquery angularjs

Datepicker获取日期并将其放入input字段。输入标记为required,但AngularJS无法查看更改并将其标记为有效。为什么呢?

HTML

<div class="form-group" ng-class="{ 'has-error': myForm.inputDatetimeStart.$invalid }">
    <label for="datetimepicker_start" class="col-sm-3 control-label">Start date and time: </label>
    <div class="col-sm-8">
        <input class="form-control" name="inputDatetimeStart" ng-model="datetime_start" id="datetimepicker_start" type="text" required>
    </div>
</div>

JS

 angular.module('myApp', ['ajoslin.promise-tracker', 'ngRoute'])
     .controller('myCtrl', function ($scope, $http, $log, promiseTracker, $timeout){
       jQuery('#datetimepicker_start').datetimepicker({   });
       ...

     }

1 个答案:

答案 0 :(得分:1)

尝试使用

$scope.$watch('datetime_start', function () { 
    $scope.$apply();
})

它会使消化周期发生。