angularJS提交表單(form)
更新時間:2015年02月09日 09:42:28 投稿:hebedich
這篇文章主要介紹了angularJS提交表單(form)的方法和示例,需要的朋友可以參考下
代碼很簡單,就不多廢話了,直接奉上代碼:
復(fù)制代碼 代碼如下:
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>無標(biāo)題文檔</title>
</head>
<script src="http://localhost:81/js/jquery.js">
</script>
<script src="http://localhost:81/js/angular.min.js">
</script>
<body ng-app="app">
<div ng-controller="TestCtrl">
<div ng-form test>
<input ng-model="a" type="email" />
<button ng-click="do()">查看</button>
</div>
</div>
<script>
app = angular.module("app",[]);
app.directive('test',function() {<br> //form表單的指令都有一個默認(rèn)的控制器作為第四個參數(shù)
var link = function($scope, $element, $attrs, $ctrl) {
$scope.do = function() {
//$ctrl.$setDirty();
console.log($ctrl.$pristine); //form是否沒被動過
console.log($ctrl.$dirty); //form是否被動過
console.log($ctrl.$valid); //form是否被檢驗通過
console.log($ctrl.$invalid); //form是否有錯誤
console.log($ctrl.$error); //form中有錯誤的字段
}
}
return {
compile: function() {
return link
},
require: 'form',
restrict: 'A'
}
});
app.controller('TestCtrl', function($scope){
//如果沒有contrller,這東西還不會初始化..
});
</script>
</body>
</html>
這里給大家分享的是最基礎(chǔ)的angularJS表單驗證,希望大家能夠喜歡。
相關(guān)文章
Angular動態(tài)添加、刪除輸入框并計算值實例代碼
這篇文章主要介紹了Angular動態(tài)添加、刪除輸入框并計算值實例代碼的相關(guān)資料,需要的朋友可以參考下2017-03-03Angularjs的Controller間通信機(jī)制實例分析
這篇文章主要介紹了Angularjs的Controller間通信機(jī)制,結(jié)合實例形式分析了Controller通信機(jī)制的原理、實現(xiàn)技巧與相關(guān)操作技巧,需要的朋友可以參考下2016-11-11AngularJs Using $location詳解及示例代碼
本文主要介紹AngularJs Using $location的知識資料,這里整理了相關(guān)的資料,及簡單示例代碼,有興趣的小伙伴可以參考下2016-09-09詳解Angular中實現(xiàn)自定義組件的雙向綁定的兩種方法
這篇文章主要介紹了詳解Angular中實現(xiàn)自定義組件的雙向綁定的兩種方法,對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2018-11-11