JSFiddle - React, Tailwind, and code Playground
by Lion Lee
HTML
<link rel="stylesheet" href="//cdn.bootcss.com/bootstrap/3.3.6/css/bootstrap.min.css">
<div class="wrapper" ng-app="myapp">
<form name="form" ng-controller="inputCtrl">
<div class="alert alert-danger" ng-show="form.txt1.$error.required">input1 is empty.</div>
<div class="alert alert-danger" ng-show="form.txt2.$error.minlength">input2 is must longer than 5</div>
<div class="form-group">
<label>input1:(设置了required属性,清空一下内容查看效果)</label>
<input type="text" name="txt1" class="form-control" ng-model="input1" required />
</div>
<div class="form-group">
<label>input2:(设置了ngMinlength属性,增加内容查看效果)</label>
<input type="text" name="txt2" class="form-control" ng-model="input2" ng-minlength="5" />
</div>
form.txt1.$error.required:{{form.txt1.$error.required}}
<br />
form.txt2.$error.minlength:{{form.txt2.$error.minlength}}
</form>
</div>
JavaScript
//input的使用,ngMinlength以及$error
var app = angular.module('myapp', []);
app.controller('inputCtrl', function($scope) {
$scope.input1 = 'required';
$scope.input2 = 'min';
});