1
我正在做一個簡單的驗證所需,但無法找到ng-Message工作在錯誤的條目或點擊提交。有人能幫我解決我錯在哪裏嗎?ngMessage不適用於AngularJs
HTML:
<html>
<head>
<!-- Script Files -->
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.4.8/angular.min.js"></script>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular-messages.js"></script>
</head>
<body ng-app="myApp" ng-controller="myCtrl">
<form name="form1" id="form1" novalidate>
<input type="text" name="age" ng-minlength="3" required/>
<div ng-messages="form1.age.$error" ng-show="(form1.age.$error.required || form1.age.$error.minlength) && (form1.age.$touched || form1.$submitted) " >
<div ng-message="required">This is required</div>
<div ng-message="minlength">Length is too less</div>
</div>
<a data-ng-click="submit(form1.$invalid)">Click</a>
</form>
<script>
//module declaration
var app = angular.module('myApp', ['ngMessages']);
//controller declaration
app.controller('myCtrl', function($scope) {
var submit = function(invalid){
if(invalid) return;
}
});
</script>
</body>
</html>
添加角度消息js文件。 //ajax.googleapis.com/ajax/libs/angularjs/XYZ/angular-messages.js –
[ng-message未顯示]的可能重複(http://stackoverflow.com/questions/35746963/ng-message-是不顯示) – Zakaria
這個問題是完全不同的。 Mine更簡單,並且與基於$ touch和integer操作的單個輸入的驗證相關。 – Deadpool