我試圖驗證我的表單,如果這些字段是有效的,那麼它應該將數據發佈到數據庫,如果不阻止將數據發佈到數據庫。當我提交表格我得到一個錯誤TypeError: Cannot read property '$valid' of undefined
,我不知道如何克服它,需要幫助。表單驗證使用angularjs
HTML:
<form name="formvalidation">
<ion-view ng-controller="ValidationCheck">
<ion-content>
<div>
<strong>User:</strong> <br/>
<input ng-model="name" type="text" name="name" required/>
<ng-messages for="formvalidation.name.$error" ng-if="formvalidation.name.$invalid">
<div ng-messages-include="error/validation.html"></div>
<ng-messages>
</div>
</from>
<button ng-click="check()">
控制器:
myApp.controller('ValidationCheck',function($scope, applicationService)
{
$scope.check=function(formvalidation){
var name={'name'=$scope.name};
$scope.submitted=true;
if(formvalidation.$valid){
applicationService.save(name,$scope.home);
}}});