Angularjs 事件指令 input 相關指令 和樣式指令 DOM 操作指令詳解

來源:互聯網
上載者:User

Angularjs 事件指令 input 相關指令 和樣式指令 DOM 操作指令詳解
Angularjs 事件指令 input 相關指令 和樣式指令DOM 操作指令詳解學習要點:1. AngularJs 事件指令2. input 相關指令3. 樣式指令4. DOM 操作指令5. ngBind/ngBindHtml/ngBindTemplate 重點6. ng-init ng-mode ng-model-options ng-controler1. Angularjs 事件指令自己研究:ng-click/dbclickng-mousedown/upng-mouseenter/leaveng-mousemove/over/outng-keydown/up/pressng-focus/blurng-submit重點講述:ng-selectedng-changeng-copyng-cutng-pasteng-cloak 在 angular 中為我們提供了 ng-cloak 來實現紡織閃爍的方案,我們只需要在需要的地方加上 ng-cloak。同時對於 bing 文字({{ express }} )我們也可以改為 ng-bind來實現避免。ng-non-bindable 如果我們就想要一個{{}} 這樣的內容就可以使用 ng-clock<input type="checkbox" ng-model="aaa"><select><option>11111</option><option ng-selected="aaa">22222</option></select><input type="text" ng-change="bbb='hello'" ng-model="bbb">{{bbb}}<br><input type="text" value="aasdassssssss" ng-paste="ccc=true">{{ccc}}2. Angularjs input 相關指令ng-disabledng-readonlyng-checkedng-value<!DOCTYPE html><html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><title>無標題文檔</title><script type="text/javascript" src="../angular.min.js"></script></head><body><div ng-app="myApp"><div ng-controller="firstController"><input type="button" ng-value="text" ng-disabled="isDisabled"><input type="text" value="{{text}}" ng-readonly="isDisabled"><input type="checkbox" value="{{text}}" ng-checked="isDisabled"></div></div><script type="text/javascript">var app = angular.module('myApp',[]);app.controller('firstController',['$scope','$interval',function($scope,$interval){var iNow = 5;$scope.text = iNow+'秒';$scope.isDisabled = true;//setInterval -> $scope.$apply()//$timeout $intervalvar timer = $interval(function(){iNow--;$scope.text = iNow+'秒';if(iNow == 0){$interval.cancel(timer);$scope.text = '可以點擊啦';$scope.isDisabled = false;}},1000);}]);</script></body></html>3. Angularjs 樣式指令ng-classng-styleng-hrefng-srcng-attr-(suffix) html 中屬性可能有多了 angularjs 提供了一種通用的寫法如: ng-attr- href<!DOCTYPE HTML><html ng-app="myApp"><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"><title>無標題文檔</title><style>.red{ background:red;}.yellow{ background:yellow;}</style><script src="angular.min.js"></script><script>var m1 = angular.module('myApp',[]);m1.controller('Aaa',['$scope',function($scope){$scope.text = 'hello';$scope.style = "{color:'red',background:'yellow'}";$scope.sClass = "{red:true,yellow:true}";$scope.url = "http://www.baidu.com";}]);</script></head><body><div ng-controller="Aaa"><div ng-class="{yellow:true}">{{text}}</div><div ng-class="{red:true}">{{text}}</div><div ng-class="{{sClass}}">{{text}}</div><div ng-style="{{style}}">{{text}}</div><a ng-href="{{url}}">aaaaaaa</a><a ng-attr-href="{{url}}" ng-attr-title="{{text}}" ng-attr-class=""ng-attr-style="">aaaaaaa</a></div><script>//alert(1);</script></body></html>4. Angularjs DOM 操作指令ng-show display 隱藏顯示<div ng-show="bBtn">aaaaaaaaaaaa</div>ng-if dom 操作<div ng-if="bBtn">aaaaaaaaaaaa</div>ng-switch<div ng-switch on="bBtn"><p ng-switch-default>預設的效果</p><p ng-switch-when="false">切換的效果</p></div>ng-open<details ng-open="bBtn"><summary>Copyright 2011.</summary><p>All pages and graphics on this web site are the property ofW3School.</p></details>5. Angularjs ngBind/ngBindHtml/ngBindTemplate/ ngIncludengBind 顯示資料類似於 {{}}ngBindTemplate 解決 ng-bind 中只能綁定一個的問題ngBindHtml 解析 html 代碼ngInclude 載入外部頁面6. ng-init ng-mode ng-model-options ng-controlerng-init<script>angular.module('initExample', []).controller('ExampleController', ['$scope', function($scope){$scope.list = [['a', 'b'], ['c', 'd']];}]);</script><div ng-controller="ExampleController"><div ng-repeat="innerList in list" ng-init="outerIndex =$index"><div ng-repeat="value in innerList" ng-init="innerIndex =$index"><spanclass="example-init">list[ {{outerIndex}} ][ {{innerIndex}} ] ={{value}};</span></div></div></div>ng-mode<!DOCTYPE HTML><html ng-app="myApp"><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"><title>無標題文檔</title><style>.red{ background:red;}.yellow{ background:yellow;}</style><script src="angular.min.js"></script><script>/*var m1 = angular.module('myApp',[]);m1.controller('Aaa',['$scope',function($scope){$scope.text = 'hello';}]);*/var m1 = angular.module('myApp',[]);m1.controller('Aaa',['$scope',FnAaa]);function FnAaa($scope){}FnAaa.prototype.num = '123';FnAaa.prototype.text = 'hello';FnAaa.prototype.show = function(){return 'angularJS';};</script></head><body><!--<div ng-controller="Aaa"><input type="text" ng-model="text" ng-model-options="{updateOn : 'blur'}"><div>{{text}}</div></div>--><div ng-controller="FnAaa as a1"><div>{{a1.text}}:{{a1.show()}}</div></div></body></html>ng-model-options 控制雙向事件綁定的時候 觸發事件的方式<div ng-controller="ExampleController"><form name="userForm">Name:<input type="text" name="userName"ng-model="user.name"ng-model-options="{ updateOn: 'blur' }"ng-keyup="cancel($event)" /><br />Other data:<input type="text" ng-model="user.data" /><br /></form><pre>user.name = <span ng-bind="user.name"></span></pre></div>ng-controler

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.