• [AngularJS] Angular 1.3 $submitted for Form in Angular


    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

  • 相关阅读:
    leetcode Reverse Words in a String
    leetcode[150] Evaluate Reverse Polish Notation
    leetcode Max Points on a Line
    leetcode Sort List
    leetcode Insertion Sort List
    vs 中一些快捷键
    leetcode LRU Cache
    leetcode[145] Binary Tree Postorder Traversal
    leetcode Binary Tree Preorder Traversal
    Leetcode Reorder List
  • 原文地址:https://www.cnblogs.com/Answer1215/p/4084351.html
Copyright © 2020-2023  润新知