AngularJS输入$valid始终为false,没有错误
我试图在我的项目中应用AngularJs验证。因此编写了以下代码:AngularJS输入$valid始终为false,没有错误,angularjs,validation,angularjs-directive,frontend,Angularjs,Validation,Angularjs Directive,Frontend,我试图在我的项目中应用AngularJs验证。因此编写了以下代码: <form name="recipeTitle"> <input ng-if="edit" required type="text" ng-model="recipe.name" name="name"/> </form> <span>valid = {ng recipeTitle.name.$valid ng}</span> <span>er
<form name="recipeTitle">
<input ng-if="edit" required type="text" ng-model="recipe.name" name="name"/>
</form>
<span>valid = {ng recipeTitle.name.$valid ng}</span>
<span>errors = {ng recipeTitle.name.$error ng}</span>
当输入字段中出现任何值时,验证返回:
valid = false
errors = {}
我不知道,如何使$valid属性变为真。感谢您的帮助,谢谢。我也有同样的问题。如果您使用$scope,它将起作用:
<span>valid = {ng $scope.recipeTitle.name.$valid ng}</span>
<span>errors = {ng $scope.recipeTitle.name.$error ng}</span>
valid={ng$scope.recipeTitle.name.$valid ng}
errors={ng$scope.recipeTitle.name.$error ng}
而不是
<span>valid = {ng recipeTitle.name.$valid ng}</span>
<span>errors = {ng recipeTitle.name.$error ng}</span>
valid={ng recipeTitle.name.$valid ng}
errors={ng recipeTitle.name.$error ng}
例如,如果您提供plunker链接,将更容易为您提供帮助。。但plunker代码只需进行最少的必要更改,就可以像预期的那样工作)如果没有其他方法可以工作,那么可以通过JavaScript手动将valid设置为true,如果“errors”为空,则设置为false,否则每次输入都是空的changed@Kamilplunker中的代码工作得很好。@Rebornix是的,确实如此。我不知道我的应用程序做错了什么。谢谢你的回答。我现在无法检查它,因为我们已经制定了解决方案,但我会检查它以帮助smb。)
<span>valid = {ng recipeTitle.name.$valid ng}</span>
<span>errors = {ng recipeTitle.name.$error ng}</span>