ng-model 指令将表单元素值动态绑定到应用程序.
例 html
<div ng-app="myApp" id="do" ng-controller="myCtrl">
<input type="text" name="in" id="in" ng-model="name">
<button type="button" ng-click="check()">check</button>
</div>
例 js
var app = angular.module('myApp', []);
app.controller('myCtrl', function($scope) {
$scope.check = function () {
console.log($scope)
}
});
点击 check
输入 sth 点击 check
$scope 下新增值为 sth 的变量 name.
ng-model 指令会在当前表单元素添加无样式的类名 ng-pristine ng-untouched ng-valid.
当 input 聚焦时,无样式类名无变化;当 input 失焦时,ng-untouched 类名被移除,新增 ng-touched 无样式类名.
之后,再重复聚焦失焦操作,无样式类名不再变化.
除非刷新网页,回到初始三个无样式类名.
若有输入操作, ng-pristine 类名被移除,新增 ng-dirty ng-valid-parse 无样式类名.