表单验证不适用于IONIC,但适用于AngularJS
我必须在我的ionic应用程序中提供必填字段验证。但是,我无法使默认的角度表单验证工作。我使用了ng submit,但在ionic中,它甚至没有启动submit。 有我可以使用的指令吗表单验证不适用于IONIC,但适用于AngularJS,angularjs,ionic-v1,Angularjs,Ionic V1,我必须在我的ionic应用程序中提供必填字段验证。但是,我无法使默认的角度表单验证工作。我使用了ng submit,但在ionic中,它甚至没有启动submit。 有我可以使用的指令吗 <ion-view title="Dashboard"> <ion-content class="has-header padding"> <form name="myForm" ng-controller="DashCtrl"> <input t
<ion-view title="Dashboard">
<ion-content class="has-header padding">
<form name="myForm" ng-controller="DashCtrl">
<input type="radio" ng-model="color" value="red" required> Red <br/>
<input type="radio" ng-model="color" value="green" required> Green <br/>
<input type="radio" ng-model="color" value="blue" required> Blue <br/>
<tt>color = {{color | json}}</tt><br/>
<button type="submit" ng-click="submitForm()">Submit</button>
</form>
</ion-content>
</ion-view>
红色
绿色
蓝色
颜色={{color | json}}
提交
但是,如果它是一个AngularJS应用程序,它的工作正如预期的那样
AngularJS Plunkr:
IONIC Plunkr:对于不在IONIC check中工作的HTML5,可以从 但是,您也可以这样做: 使用
ng单击“提交表单(myForm)”
你的提交功能是这样的
$scope.submitForm = function(form) {
if (form.$valid == true){
console.log('yay')
} else {
console.log('Nyay')
}
};
用这些更改分叉您的plnkr,检查它
希望有帮助 在IONIC中,代码使用提交按钮上的
ng click
指令。在AngularJS中,代码在
元素上使用ng submit
指令。离子使用所需的;AngularJS使用ng required
。苹果变成橘子。