[AngularJS] Angular 1.3 $submitted for Form in Angular

时间:2022-10-24 15:51:44

AngularJS 1.3 add $submitted for form, so you can use  $submitted  to track whether the submit event is trggered.

Read More: https://egghead.io/lessons/angularjs-new-in-angular-1-3-updates-to-forms

<!DOCTYPE html>
<html>
<head>
<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.3.0/angular.min.js"></script>
<title>What's new in Angular 1.3</title>
</head>
<body ng-app="app" ng-controller="MainCtrl as vm">
<h1>Angular {{vm.angularVersion}}</h1>
<h2>Demo</h2> <form name="myForm" novalidate>
<label>
Some input:
<input
type="time"
name="myField"
ng-model="vm.inputValue"
ng-model-options="vm.modelOptions"
required /> </label>
<button type="submit">Submit</button>
</form> Bound value: <span ng-bind="vm.inputValue"></span> <br />
Field Error State: <pre>{{myForm.myField.$error | json}}</pre> <br />
Form Error State: <pre>{{myForm.$error | json}}</pre>
myForm.$submitted: {{myForm.$submitted}} </body>
</html>
var app = angular.module('app', []);

app.controller('MainCtrl', function MainCtrl() {
'use strict'; var vm = this;
vm.angularVersion = angular.version.full;
vm.modelOptions = {
timezone: 'UTC'
};
});
Form Error State:
{
"required": [
{
"$viewValue": "",
"$validators": {},
"$asyncValidators": {},
"$parsers": [
null,
null
],
"$formatters": [
null
],
"$viewChangeListeners": [],
"$untouched": true,
"$touched": false,
"$pristine": true,
"$dirty": false,
"$valid": false,
"$invalid": true,
"$error": {
"required": true
},
"$name": "myField",
"$options": {
"timezone": "UTC",
"updateOnDefault": true
}
}
]
}
myForm.$submitted: false

ReadMore http://jsbin.com/?html,css,js,output