在我的應用程序中我$watch
如果表格在做某些事情之前是有效的。問題是ngForm在我使用之前不會編譯models
。ngForm在型號更新之前無效
例:http://plnkr.co/edit/Y7dL67Fn7SaSEkjiFf2q?p=preview
JS
$scope.results = [];
$scope.$watch(function() {
return $scope.testForm.$valid;
},
function(valid) {
$scope.results.push(valid);
}
)
HTML
<ng-form name="testForm" ng-init="test = 1">
<input ng-model="test" required>
</ng-form>
<p ng-repeat="result in results track by $index" ng-class="{'false': !result, 'true': result}">{{ result }}</p>
結果:
false // Wrong
true
形式不應該首先是因爲$scope.test
無效設置爲1
任何線索?
這很有道理,謝謝。 – L105