如何使用angularJs
本期更新,博主將給大家分享一些AngularJs常用的一些屬性和方法,AngularJS 是由 Google 的員工 Miško Hevery 從 2009 年開(kāi)始著手開(kāi)發(fā)。這是一個(gè)非常好的構(gòu)想,該項(xiàng)目目前已由 Google 正式支持,有一個(gè)全職的開(kāi)發(fā)團(tuán)隊(duì)繼續(xù)開(kāi)發(fā)和維護(hù)這個(gè)庫(kù)。AngularJS 是一個(gè) JavaScript 框架。它是一個(gè)以 JavaScript 編寫(xiě)的庫(kù)。因此,有一定JavaScript基礎(chǔ)的朋友會(huì)更容易理解,其中的一些用法也可參照J(rèn)avascript的使用方法。
一、AngularJS入門(mén)之指令與表達(dá)式
AngularJS 通過(guò) 指令 擴(kuò)展了 HTML,且通過(guò) 表達(dá)式 綁定數(shù)據(jù)到 HTML。
【AngularJS常用指令】
1、ng-app:聲明Angular所管轄的區(qū)域。一般寫(xiě)在body或html上,原則上一個(gè)頁(yè)面只有一個(gè);
<body ng-app=""></body>
2、ng-model:把元素值(比如輸入域的值)綁定到應(yīng)用程序的變量中。
<input type="text" ng-model="name"/>
3、ng-bind:把應(yīng)用程序變量中的數(shù)據(jù)綁定到 HTML視圖中??捎帽磉_(dá)式{{ }}替代;
<div ng-bind="name"></div>
<div>{{name}}</div>4、ng-init:初始化 AngularJS應(yīng)用程序中的變量。
<body ng-app="" ng-init="name=123">
5、表達(dá)式: {{}} 綁定表達(dá)式,可以包含文字、運(yùn)算符和變量。但表達(dá)式在網(wǎng)頁(yè)加載瞬間會(huì)看到{{}},所以可以用ng-bind=""替代
{{ 5 +""+ 5 + ',Angular'}}
【基本概念】
1、指令:AngularJS中,通過(guò)擴(kuò)展HTML的屬性提供功能。所以,ng-開(kāi)頭的新屬性,被我們成為指令
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>AngularJS入門(mén)</title>
</head>
<body ng-app="" ng-init="name=123">
<input type="text" id="input" ng-model="name"/>
<div id="div" ng-bind="name+',Angular'">{{name}}</div>
<input type="text" id="input2" ng-model="name"/>
<p>我的第一個(gè)表達(dá)式: {{ 5 +""+ 5 + ',Angular'}}</p>
</body>
<script src="libs/jquery-3.1.1.js"></script>
<script src="libs/angular.js"></script>
<script type="text/javascript">
// var input1 = document.getElementById("input");
// var div = document.getElementById("div");
//
// input1.onkeyup = function(){
// div.innerHTML = input1.value;
// }
// $("#input").keyup(function(){
// $("#div").html($("input").val());
// });
</script>
</html>二、AngularJS中的MVC與作用域
[MVC三層架構(gòu)]
1、Model(模型):應(yīng)用程序中用于處理數(shù)據(jù)的部分。(保存或修改數(shù)據(jù)到數(shù)據(jù)庫(kù)、變量等)。AngularJS中的Model特指的是:數(shù)據(jù)
View(視圖):用戶看到的用于顯示數(shù)據(jù)的頁(yè)面;
Controller(控制器):應(yīng)用程序中處理用戶交互的部分。負(fù)責(zé)從視圖讀取數(shù)據(jù),控制用戶輸入,并向模型發(fā)送數(shù)據(jù)。
2、工作原理: 用戶從視圖層發(fā)出請(qǐng)求,controller接收到請(qǐng)求后轉(zhuǎn)發(fā)給對(duì)應(yīng)的model處理,model處理完成后返回結(jié)果給controller,并在view層反饋給用戶。
主要用于CRUD類應(yīng)用,不適合游戲開(kāi)發(fā)和DOM操作
創(chuàng)建一個(gè)Angular模塊,即ng-app所綁定的部分,需傳遞兩個(gè)參數(shù):
① 模塊名稱,即ng-app所需要綁定的名稱。ng-app="myApp"
② 數(shù)組:需要注入的模塊名稱,不需要可為空。
var app = angular.module("myApp",[]);
在Angular模塊上,創(chuàng)建一個(gè)控制器Controller,需要傳遞兩個(gè)參數(shù)
① Controller名稱,即ng-controller需綁定的名稱。ng-controller="myCtrl"
② Controller的構(gòu)造函數(shù):構(gòu)造函數(shù)可以傳入多個(gè)參數(shù),包括$scope/$rootScope以及各種系統(tǒng)內(nèi)置對(duì)象;
[AngularJS中的作用域]
① $scope:局部作用域,聲明在$scope上的屬性和方法,只能在當(dāng)前Controller中使用;
② $rootScope:根作用域,聲明在$rootScope上的屬性和方法,可以在ng-app所包含的任何區(qū)域使用(無(wú)論是否同一Controller,或是否在Controller包含范圍中)。
>>> 若沒(méi)有使用$scope聲明變量,而直接在html中使用ng-model綁定的變量作用域?yàn)椋?/p>
1.如果ng-model在某個(gè)ng-controller中,則此變量會(huì)默認(rèn)綁定到當(dāng)前Controller的$scope上;
2.如果ng-model沒(méi)有在任何一個(gè)ng-controller鐘,則此變量將綁定在$rootScope上;
app.controller("myCtrl",function($scope,$rootScope){
//$scope.name = "name1";
$rootScope.age = 14;
$scope.classes = {
name:"H51701",
num:"33"
};
});
app.controller("myCtrl1",function(){
});
三、Angular過(guò)濾器
AngularJS中,過(guò)濾器可以使用一個(gè)管道字符(|)添加到表達(dá)式和指令中。
>>> 系統(tǒng)內(nèi)置過(guò)濾器:
currency 格式化數(shù)字為貨幣格式。
filter 從數(shù)組項(xiàng)中選擇一個(gè)子集。
lowercase 格式化字符串為小寫(xiě)。
orderBy 根據(jù)某個(gè)表達(dá)式排列數(shù)組。
uppercase 格式化字符串為大寫(xiě)。
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
<link rel="stylesheet" href="css/bootstrap.css" rel="external nofollow" />
</head>
<body ng-app="app" ng-controller="ctrl">
<p>{{"aBcDeF"|uppercase}}</p>
<p>{{"aBcDeF"|lowercase}}</p>
<p>{{123456|currency}}</p>
<form class="form-horizontal">
</form>
<div class="form-group">
<label>請(qǐng)輸入篩選信息:</label>
<input type="text" ng-model="search" />
</div>
<table class="table table-bordered">
<thead>
<tr>
<th>姓名</th>
<th>年齡</th>
<th>成績(jī)</th>
</tr>
</thead>
<tr ng-repeat="item in classes| filter:search | orderBy:'score'">
<td>{{item.name}}</td>
<td>{{item.age}}</td>
<td>{{item.score}}</td>
</tr>
</table>
<p>{{"123456"|reverse}}</p>
</body>
<script src="libs/angular.js"></script>
<script>
angular.module("app",[])
.controller("ctrl",function($scope){
$scope.classes = [
{name:"張二",age:"12",score:"88"},
{name:"張三",age:"12",score:"88"},
{name:"李四",age:"15",score:"78"},
{name:"李五",age:"15",score:"78"},
{name:"王麻子",age:"18",score:"98"},
{name:"王二麻子",age:"18",score:"98"}
];
})
/*
* 自定義過(guò)濾器
*/
.filter('reverse', function() {
return function(text) {
if(!angular.isString(text)){
return "您輸入的內(nèi)容不是字符串";
}else{
return text.split("").reverse().join("");
}
}
})
</script>
</html>四、Angular服務(wù)Service
【服務(wù)Service】
1、內(nèi)置服務(wù):
>>>使用內(nèi)置服務(wù)必須在controlller中通過(guò)函數(shù)的參數(shù)注入進(jìn)來(lái)?。。?!
$location :返回當(dāng)前頁(yè)面的 URL 地址;
$http: 服務(wù)器請(qǐng)求數(shù)據(jù),類似于AJax;
$timeout :對(duì)應(yīng)了 JS window.setTimeout 函數(shù)。
$interval :對(duì)應(yīng)了 JS window.setInterval 函數(shù)。
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
</head>
<body ng-app="app" ng-controller="ctrl">
<pre >{{local}}</pre>
<p ng-bind="myHeader"></p>
<p ng-bind="num"></p>
<p >{{gongneng}}</p>
<p>將255轉(zhuǎn)為16進(jìn)制:{{hexafy}}</p>
<p>{{123|filt}}</p>
<p>{{123|filt1}}</p>
</body>
<script type="text/javascript" src="libs/angular.js" ></script>
<script type="text/javascript">
angular.module("app",[])
.controller("ctrl",function ($scope,$location,$timeout,$interval,$hexafy) {
$scope.local=$location.absUrl();
$scope.myHeader = "Hello World!";
$timeout(function () {
$scope.myHeader = "How are you today?";
}, 2000);
$scope.num=0;
$interval(function () {
$scope.num++;
},1000);
$scope.gongneng=$hexafy.$$gongneng;
$scope.hexafy=$hexafy.myFunc(255);
})
/*自定義服務(wù)*/
.service('$hexafy', function() {
this.$$gongneng = "將轉(zhuǎn)入的數(shù)字,轉(zhuǎn)為16進(jìn)制";
this.myFunc = function (x) {
return x.toString(16);
}
})
.filter("filt",function(){
return function(x){
return x.toString(16);
}
})
/*在過(guò)濾器中,調(diào)用自定義服務(wù)*/
.filter("filt1",function($hexafy){
return function(x){
return $hexafy.myFunc(x);
}
})
</script>
</html>【自定義服務(wù)factory】
factory 是一個(gè)函數(shù)用于返回值,通常我們使用 factory 函數(shù)來(lái)計(jì)算或返回值。(factory使用上,與service差距不大)
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
<link rel="stylesheet" href="libs/bootstrap.css" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" />
</head>
<body ng-app="app" ng-controller="ctrl">
<p>
[功能]<br/>
{{gongneng}}
</p>
<p>
255轉(zhuǎn)成16進(jìn)制為:{{num}}
</p>
</body>
<script src="libs/angular.js"></script>
<script>
angular.module("app",[])
.config()
.controller("ctrl",function($scope,hexafy){
$scope.gongneng = hexafy.gongneng;
$scope.num = hexafy.myFunc(255);
})
.factory('hexafy',function(){
var obj = {
gongneng : "將轉(zhuǎn)入的數(shù)字,轉(zhuǎn)為16進(jìn)制",
myFunc:function(x){
return x.toString(16);
}
};
return obj;
})
</script>
</html>【自定義服務(wù)provide】
1、在AngularJS中,Service,factory都是基于provider實(shí)現(xiàn)的。
2、在provider中,通過(guò)$get()方法提供了factory的寫(xiě)法,用于返回 value/service/factory。;
3、provider是三種自定義服務(wù)中,唯一可以寫(xiě)進(jìn)config配置階段的一種。
如果服務(wù),必須要在配置階段執(zhí)行,那么必須使用provider。否則,一般使用Service或factory
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
<link rel="stylesheet" href="libs/bootstrap.css" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" />
</head>
<body ng-app="app" ng-controller="ctrl">
<p>
[功能]<br/>
{{gongneng}}
</p>
<p>
255轉(zhuǎn)成16進(jìn)制為:{{num}}
</p>
</body>
<script src="libs/angular.js"></script>
<script>
angular.module("app",[])
/*在配置階段聲明procide服務(wù)!*/
.controller("ctrl",function($scope,hexafy){
$scope.gongneng = hexafy.gongneng;
$scope.num = hexafy.myFunc(255);
})
/*定義一個(gè)provider服務(wù)*/
.provider('hexafy',function(){
// this.gongneng = "將轉(zhuǎn)入的數(shù)字,轉(zhuǎn)為16進(jìn)制";
this.$get = function(){
var obj = {
gongneng : "將轉(zhuǎn)入的數(shù)字,轉(zhuǎn)為16進(jìn)制",
myFunc : function(x){
return x.toString(16);
}
}
return obj;
}
})
</script>
</html>五、Angular中的$http
$http 是 AngularJS 中的一個(gè)核心服務(wù),用于讀取遠(yuǎn)程服務(wù)器的數(shù)據(jù)。
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
<link rel="stylesheet" href="libs/bootstrap.css" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" />
</head>
<body ng-app="app" ng-controller="ctrl">
<!--<pre>
{{data}}
</pre>-->
<div class="container" style="margin-top: 50px;">
<div class="panel panel-primary" >
<div class="panel-heading">
<div class="panel-title" style="text-align: center;">H5-1701班級(jí)信息表</div>
</div>
<div class="panel-body">
<table class="table table-bordered">
<thead>
<tr>
<th>姓名</th>
<th>年齡</th>
<th>愛(ài)好</th>
<th>語(yǔ)文成績(jī)</th>
<th>數(shù)學(xué)成績(jī)</th>
<th>總分</th>
</tr>
</thead>
<tr ng-repeat="item in data | orderBy:'score.chinese + score.math'">
<td ng-bind="item.name"></td>
<td ng-bind="item.age"></td>
<td ng-bind="item.hobby">
<!--<span ng-repeat="a in item.hobby">{{a}}</span>-->
</td>
<td ng-bind="item.score.chinese"></td>
<td ng-bind="item.score.math"></td>
<td ng-bind="item.score.chinese + item.score.math"></td>
</tr>
</table>
</div>
</div>
</div>
</body>
<script src="libs/angular.js"></script>
<script>
angular.module("app",[])
.controller("ctrl",function($scope,$http){
$http.post('h51701.json',{/*傳遞的參數(shù)對(duì)象*/})
.then(function(res){
$scope.data = res.data;//data 從返回的信息中,取出需要的數(shù)據(jù)。為JSON對(duì)象(數(shù)組)
});
})
</script>
</html>六、Angular中的select
使用數(shù)組作為數(shù)據(jù)源。
其中,x表示數(shù)組的每一項(xiàng)。
默認(rèn)會(huì)將x直接綁定到option的value中。
而option顯示的內(nèi)容,有前面的x for... 決定
<select ng-model="name" ng-options="x.site for x in sites"> </select>
使用對(duì)象作為數(shù)據(jù)源.
其中,(x,y)表示鍵值對(duì),x為鍵,y為值。
默認(rèn)會(huì)將值y綁定到option的value中.
而option顯示的內(nèi)容,有前面的x for... 決定
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
<link rel="stylesheet" href="libs/bootstrap.css" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" />
<style type="text/css">
*{
margin: 10px;
}
</style>
</head>
<body ng-app="app" ng-controller="ctrl">
<select ng-model="name" ng-options="x for (x, y) in sites">
</select>
<div class="alert alert-info" style="width: 300px;">
您選擇的是:{{name}}
</div>
<table class="table table-bordered">
<tr>
<th>序號(hào)</th>
<th>姓名</th>
</tr>
<tr ng-repeat="item in options">
<td>{{$index +1}}</td><!--$index 表示遍歷的索引,從0開(kāi)始-->
<td>{{item}}</td>
</tr>
</table>
</body>
<script src="libs/angular.js"></script>
<script>
angular.module("app",[])
.controller("ctrl",function($scope){
$scope.options = ["張三","李四","王二麻子","杰小瑞"];
$scope.sites = {
site01 : "Google",
site02 : "Runoob",
site03 : "Taobao"
};
})
</script>
</html>七、Angular中的DOM與事件
ng-disabled="true/false" 當(dāng)傳入true時(shí),控件禁用。傳入false是,啟用;
ng-show 默認(rèn)隱藏 傳入true時(shí)顯示;
ng-hide 默認(rèn)顯示 傳入true是隱藏;
ng-click定義了AngularJS中的點(diǎn)擊事件。
只能觸發(fā)綁定在Angular作用域中的屬性與方法。
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
<link rel="stylesheet" href="libs/bootstrap.css" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" />
<style type="text/css">
*{
margin: 10px;
}
</style>
</head>
<body ng-app="app" ng-controller="ctrl">
<input type="checkbox" ng-model="mySwitch">是否同意我是帥哥!
</label>
<button ng-disabled="!mySwitch" class="btn btn-primary">點(diǎn)我!</button>
<p></p>
<label>
<input type="checkbox" ng-model="mySwitch1">是否顯示?
</label>
<button ng-show="mySwitch1" class="btn btn-primary">點(diǎn)我!</button>
<p></p>
<label>
<input type="checkbox" ng-model="mySwitch2">是否隱藏?
</label>
<button ng-hide="mySwitch2" class="btn btn-primary">點(diǎn)我!</button>
<p></p>
<button ng-click="count = count + 1">點(diǎn)我!</button>
<p>{{ count }}</p>
<button ng-click="func()">說(shuō)一下感想吧!</button>
</body>
<script src="libs/angular.js"></script>
<script>
angular.module("app",[])
.controller("ctrl",function($scope,$rootScope){
$scope.count = 10;
$scope.func = function(){
alert("我彈了一個(gè)窗!");
}
})
</script>
</html>八、Angular表單和輸入驗(yàn)證
[AngularJS中的表單驗(yàn)證]
1、表單中,常用的驗(yàn)證操作:
$dirty 表單有填寫(xiě)記錄
$valid 字段內(nèi)容合法的
$invalid 字段內(nèi)容是非法的
$pristine 表單沒(méi)有填寫(xiě)記錄
$error 表單驗(yàn)證不通過(guò)的錯(cuò)誤信息
2、驗(yàn)證時(shí),需給表單,及需要驗(yàn)證的input,設(shè)置name屬性:
給form及input設(shè)置name后,會(huì)將form表單信息,默認(rèn)綁定到$scope作用域中。故,可以使用 formName.inputName.$驗(yàn)證操作 得到驗(yàn)證結(jié)果:
例如:formName.inputName.$dirty = "true" 表單被填寫(xiě)過(guò)
formName.inputName.$invalid = "true" 表單輸入不合法
formName.inputName.$error.required = "true" 表單必填但未填
$error支持的驗(yàn)證有:required/minlength/maxlength/pattern/email/number/date/url等。。。
3、為避免沖突,例如使用type="email"時(shí),H5也會(huì)進(jìn)行驗(yàn)證操作。如果只想使用AngularJS驗(yàn)證,可以使用<form novalidate></form>屬性,禁用H5自帶驗(yàn)證功能;
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
<link rel="stylesheet" href="libs/bootstrap.css" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" />
<style type="text/css">
.row{
margin-bottom: 10px;
}
.row .col-xs-5{
text-align: center;
}
.suc{
border-color: #3c763d;
-webkit-box-shadow: inset 0 1px 1px rgba(0, 0, 0, .075);
box-shadow: inset 0 1px 1px rgba(0, 0, 0, .075);
}
.suc:focus{
border-color: #2b542c;
-webkit-box-shadow: inset 0 1px 1px rgba(0, 0, 0, .075), 0 0 6px #67b168;
box-shadow: inset 0 1px 1px rgba(0, 0, 0, .075), 0 0 6px #67b168;
}
.err{
border-color: #a94442;
-webkit-box-shadow: inset 0 1px 1px rgba(0, 0, 0, .075);
box-shadow: inset 0 1px 1px rgba(0, 0, 0, .075);
}
.err:focus{
border-color: #843534;
-webkit-box-shadow: inset 0 1px 1px rgba(0, 0, 0, .075), 0 0 6px #ce8483;
box-shadow: inset 0 1px 1px rgba(0, 0, 0, .075), 0 0 6px #ce8483;
}
</style>
</head>
<body ng-app="app" ng-controller="ctrl">
<div class="container" style="width: 40%; margin: 50px auto; padding: 0px;">
<div class="panel panel-primary">
<div class="panel-heading">
<div class="panel-title" style="text-align: center;">
用戶注冊(cè)
</div>
</div>
<div class="panel-body">
<form action="" method="get" class="form-horizontal" name="myForm" novalidate>
<div class="row" >
<div class="col-xs-3">
用戶名:
</div>
<div class="col-xs-9">
<input type="text" class="form-control" ng-model="user.name" name="name" ng-minlength="4" ng-maxlength="10" required ng-class="{suc:myForm.name.$valid && myForm.name.$dirty,err:myForm.name.$invalid && myForm.name.$dirty}"/>
<p style="color: red; margin: 0px;" ng-show="myForm.name.$invalid && myForm.name.$dirty">
<!--當(dāng)有填寫(xiě)記錄且不合法時(shí),p顯示-->
<span ng-show="myForm.name.$error.required">用戶名必須填寫(xiě)?。?!</span>
<span ng-show="myForm.name.$error.minlength">用戶名最少包含4個(gè)字符?。?!</span>
<span ng-show="myForm.name.$error.maxlength">用戶名最多包含10個(gè)字符?。。?lt;/span>
</p>
</div>
</div>
<div class="row">
<div class="col-xs-3">
郵箱:
</div>
<div class="col-xs-9">
<input type="email" class="form-control" ng-model="user.mail" name="mail" required ng-class="{suc:myForm.mail.$valid && myForm.mail.$dirty,err:myForm.mail.$invalid && myForm.mail.$dirty}"/>
<p style="color: red; margin: 0px;" ng-show="myForm.mail.$invalid && myForm.mail.$dirty">
<!--當(dāng)有填寫(xiě)記錄且不合法時(shí),p顯示-->
<span ng-show="myForm.mail.$error.required">郵箱必須填寫(xiě)?。。?lt;/span>
<span ng-show="myForm.mail.$error.email">郵箱格式不合法?。?!</span>
</p>
</div>
</div>
<div class="row">
<div class="col-xs-3">
密碼:
</div>
<div class="col-xs-9">
<input type="password" class="form-control" ng-model="user.pwd" name="pwd" pattern="^\w{6,18}$" required ng-class="{suc:myForm.pwd.$valid && myForm.pwd.$dirty,err:myForm.pwd.$invalid && myForm.pwd.$dirty}"/>
<p style="color: red; margin: 0px;" ng-show="myForm.pwd.$invalid && myForm.pwd.$dirty">
<!--當(dāng)有填寫(xiě)記錄且不合法時(shí),p顯示-->
<span ng-show="myForm.pwd.$error.pattern">密碼應(yīng)為6-18位,且只能為字母、數(shù)字、下劃線</span>
</p>
</div>
</div>
<div class="row">
<div class="col-xs-3">
確認(rèn)密碼:
</div>
<div class="col-xs-9">
<input type="password" class="form-control" ng-model="rePwd" name="rePwd" required ng-class="{suc:myForm.rePwd.$dirty&&rePwd==user.pwd,err:myForm.rePwd.$dirty&&rePwd!=user.pwd}"/>
<p style="color: red; margin: 0px;" ng-show="myForm.rePwd.$dirty && rePwd!=user.pwd">
<!--當(dāng)有填寫(xiě)記錄且不合法時(shí),p顯示-->
兩次密碼輸入不一致?。?!
</p>
</div>
</div>
<div class="row">
<div class="col-xs-5">
<input type="submit" value="注冊(cè)" class="btn btn-success" ng-disabled="myForm.$invalid || rePwd!=user.pwd" />
</div>
<div class="col-xs-5">
<input type="button" value="重置" class="btn btn-warning" ng-click="resets()" />
</div>
</div>
</form>
</div>
</div>
<pre>
{{user.pwd}}
</pre>
</div>
</body>
<script src="libs/angular.js"></script>
<script>
$scope.resets = function(){
$scope.user = angular.copy($scope.initUser);
}
$scope.resets();
})
</script>
</html>以上就是本文的全部?jī)?nèi)容,希望本文的內(nèi)容對(duì)大家的學(xué)習(xí)或者工作能帶來(lái)一定的幫助,同時(shí)也希望多多支持腳本之家!
相關(guān)文章
詳解Angular CLI + Electron 開(kāi)發(fā)環(huán)境搭建
本篇文章主要介紹了Angular CLI + Electron 開(kāi)發(fā)環(huán)境搭建,具有一定的參考價(jià)值,有興趣的可以了解一下2017-07-07
如何在AngularJs中調(diào)用第三方插件庫(kù)
在AngularJs中我們會(huì)不可避免的使用第三方庫(kù),這篇文章主要介紹了如何在AngularJs中調(diào)用第三方插件庫(kù),有興趣的可以了解下2017-05-05
angular報(bào)錯(cuò)can't resolve all parameters&nb
這篇文章主要介紹了angular報(bào)錯(cuò)can't resolve all parameters for []的解決方案,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2023-03-03
angular2+node.js express打包部署的實(shí)戰(zhàn)
本篇文章主要介紹了angular2+node.js express打包部署的實(shí)戰(zhàn),小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2017-07-07
詳解Angular路由 ng-route和ui-router的區(qū)別
這篇文章主要介紹了詳解Angular路由 ng-route和ui-router的區(qū)別,分別介紹了兩種路由的用法和區(qū)別,有興趣的可以了解一下2017-05-05
Angular利用內(nèi)容投射向組件輸入ngForOf模板的方法
本篇文章主要介紹了Angular利用內(nèi)容投射向組件輸入ngForOf模板的方法,小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2018-03-03
AngularJs中 ng-repeat指令中實(shí)現(xiàn)含有自定義指令的動(dòng)態(tài)html的方法
今天用angular寫(xiě)table的時(shí)候,遇到了一個(gè)問(wèn)題。在ng-repeat中,含有動(dòng)態(tài)的html,而這些html中含有自定義指令,怎么實(shí)現(xiàn)呢?下面小編給大家分享AngularJs中 ng-repeat指令中實(shí)現(xiàn)含有自定義指令的動(dòng)態(tài)html的方法,一起看看吧2017-01-01

