AngularJS基礎(chǔ) ng-model 指令詳解及示例代碼
AngularJS ng-model 指令
AngularJS 實(shí)例
綁定輸入框的值到 scope 變量中:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<script src="http://apps.bdimg.com/libs/angular.js/1.4.6/angular.min.js"></script>
</head>
<body>
<div ng-app="myApp" ng-controller="myCtrl">
<input ng-model="name">
<p>input 輸入框的值綁定了變量 "name" :</p>
{{name}}
</div>
<script>
var app = angular.module('myApp', []);
app.controller('myCtrl', function($scope) {
$scope.name = "John Doe";
});
</script>
<p>該實(shí)例演示了如何使用 ng-model 指令綁定輸入框的值到 scope 變量中。</p>
</body>
</html>
定義和用法
ng-model 指令綁定了 HTML 表單元素到 scope 變量中。
如果 scope 中不存在變量, 將會(huì)創(chuàng)建它。
語法
<element ng-model="name"></element>
<input>, <select>, <textarea>, 元素支持該指令。
參數(shù)值
| 值 | 描述 |
|---|---|
| separator | 你想要綁定到表單域的屬性名。 |
以上就是對(duì)AngularJS ng-model資料的整理,后續(xù)繼續(xù)補(bǔ)充相關(guān)資料。
- 深入理解AngularJS中的ng-bind-html指令
- 深入理解AngularJS中的ng-bind-html指令和$sce服務(wù)
- AngularJS ng-bind-template 指令詳解
- AngularJS ng-bind-html 指令詳解及實(shí)例代碼
- AngularJS ng-bind 指令簡(jiǎn)單實(shí)現(xiàn)
- ANGULARJS中用NG-BIND指令實(shí)現(xiàn)單向綁定的例子
- Angular.js回顧ng-app和ng-model使用技巧
- angularjs在ng-repeat中使用ng-model遇到的問題
- Angular中ng-bind和ng-model的區(qū)別實(shí)例詳解
相關(guān)文章
Angular.js中angular-ui-router的簡(jiǎn)單實(shí)踐
本篇文章主要介紹了Angular.js中angular-ui-router的簡(jiǎn)單實(shí)踐,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2017-07-07
教你用AngularJS框架一行JS代碼實(shí)現(xiàn)控件驗(yàn)證效果
簡(jiǎn)單來說Angular.js是google開發(fā)者設(shè)計(jì)和開發(fā)的一套前端開發(fā)框架,幫助你簡(jiǎn)化前端開發(fā)的負(fù)擔(dān)。到底能簡(jiǎn)化到什么程度呢,今天我們來看下,一行代碼實(shí)現(xiàn)控件驗(yàn)證效果,有木有嚇尿?2014-06-06

