<body>
or <html>標籤。
angular.bootstrap來代替。
angular.module中有跟多的信息
下面的這個例子中,
若是ngApp指令沒有放在html文檔不會被編譯,AppController將不可以被實例化爲
{{ a+b }} 等於 3
因此要這麼寫
angular.module('ngAppDemo', []).controller('ngAppDemoController', function($scope) { $scope.a = 1; $scope.b = 2; });
<ANY ng-app=""> ... </ANY>
Param | Type | Details |
---|---|---|
ngApp | angular.Module | 可配置應用程序模塊被載入javascript |
修改A標籤的默認行爲,阻止默認動做當Href屬性爲空的時候。css
<a href="" ng-click="list.addItem()">Add Item</a>
<a> ... </a>
///////////////////////////////////////////////////////
<body ng-app="ngAppDemo">
<div ng-controller="ngAppDemoController">
<a href="" ng-click="list.addItem()">Add Item</a>
</div>
<script type="text/javascript">
angular.module('ngAppDemo', []).controller('ngAppDemoController', function($scope) {
$scope.list = {
addItem: function() {
alert("test");
}
}
});
</script>
</body>
Angular是用{{}}來標記的,在用戶點擊的時候angrual還咩有去替換href屬性中{{}}值。這樣html
angular替換連接就被失敗了,一般顯示爲 404 錯誤java
ngHref指令將解決這個問題 (指令由angrular自帶的,也有本身定義的 往後會知道指令的重要性)
錯誤的寫法是:angularjs
<a href="http://www.gravatar.com/avatar/{{hash}}"/>
正確的方法去寫它:web
<a ng-href="http://www.gravatar.com/avatar/{{hash}}"/>
<A ng-href=""> ... </A>
Param | Type | Details |
---|---|---|
ngHref | template |
任何字符串能夠包含{{}}裏。
|
不建議的寫法:正則表達式
<img src="http://www.gravatar.com/avatar/{{hash}}"/>
<img ng-src="http://www.gravatar.com/avatar/{{hash}}"/>
ng-src=""> ... </IMG>Arguments
Param | Type | Details |
---|---|---|
ngSrc | template | 任何字符串能夠包含在 |
不建議的寫法:express
<img srcset="http://www.gravatar.com/avatar/{{hash}} 2x"/>
建議的方案:bootstrap
<img ng-srcset="http://www.gravatar.com/avatar/{{hash}} 2x"/>
<IMG ng-srcset=""> ... </IMG>
Param | Type | Details |
---|---|---|
ngSrcset | template | 任何字符串能夠包含在 |
<div ng-init="scope = { isDisabled: false }">
<button disabled="{{scope.isDisabled}}">Disabled</button>
</div>
<INPUT ng-disabled=""> ... </INPUT>
///////////////////////////////////////////////////////
Click me to toggle: <input type="text" ng-model="youname"><br/>
{{youname}}
<button ng-disabled="youname">Button</button>
ng-disabled="youname"寫成字符串的時候就能夠實現,若是用{{}}就不可用。
Param | Type | Details |
---|---|---|
ngDisabled | expression | 若是表達式爲真,那麼這個特別的屬性「disabled」將被禁用 |
Directive Info
<INPUT ng-checked=""> ... </INPUT>
//////////////////////////////////////
Check me to check both: <input type="checkbox" ng-model="master"><br/> <input id="checkSlave" type="checkbox" ng-checked="master">
Param | Type | Details |
---|---|---|
ngChecked | xpression | 若是表達式爲真,那麼這個特別的屬性「checked」 將被設置 |
eadonly
的屬性,這種互補的指令不會被瀏覽器撤銷,所以
Directive Info
<INPUT ng-readonly=""> ... </INPUT>
//////////////////////////////////////////////////
Check me to make text readonly: <input type="checkbox" ng-model="checked"><br/> <input type="text" ng-readonly="checked" value="I'm Angular"/>
Arguments
Param | Type | Details |
---|---|---|
ngReadonly | expression | 若是表達式爲真,那麼這個特別的屬性「checked」 將被設置 |
Param | Type | Details |
---|---|---|
ngSelected | expression | 若是表達式爲真,那麼這個特別的屬性「selected」 將被設置 |
<ng-form [name=""]> ... </ng-form>as attribute: //做爲屬性
<ANY [ng-form=""]> ... </ANY>as CSS class://做爲累,樣式
<ANY class="[ng-form: ;]"> ... </ANY>
Param | Type | Details |
---|---|---|
ngForm | name
(optional)
|
string |
表單的名稱,若是指定,控制器將發表形式到相關名字範圍,
|
<textarea ng-model="" [name=""] [required=""] [ng-required=""] [ng-minlength=""] [ng-maxlength=""] [ng-pattern=""] [ng-change=""] [ng-trim=""]> ... </textarea>
Param | Type | Details |
---|---|---|
ngModel | string | 可指定的angular數據綁定表達式 |
name
(optional)
|
string |
屬性名的形式控制發表。
|
required
(optional)
|
string | 若是你的值沒有鍵入,那麼設置 required 驗證錯誤的關鍵 |
ngRequired
(optional)
|
string |
添加所需的屬性,要求驗證約束元素ngRequired表達式的求值結果爲true。使用ngRequired而不是必需的當你想要數據綁定到所需的屬性。
|
ngMinlength
(optional)
|
number | 若是鍵入值比最短輸入值還少的話,設置的 minlength 就會生效提示錯誤 |
ngMaxlength
(optional)
|
number | 若是鍵入值比最短輸入值還多的話,設置的 maxlength 就會生效提示錯誤 |
ngPattern
(optional)
|
string | 若是不匹配正則,pattern 錯誤就會生效,預期值/正則表達式/內聯模式或者regexp模式定義爲範圍表達式。 |
ngChange
(optional)
|
string | Angular表達式被執行當輸入發生變化時因爲輸入用戶交互元素。 |
ngTrim
(optional)
|
boolean | 若是設置爲false Angular不會減小Input的輸入【減小兩遍的空格】 (default: true)--->默認爲true |
input控制着一下的一些HTML5表單類型以及對一個老版本的HTML5的驗證行爲。
<ng-form [name=""]> ... </ng-form>as attribute: //做爲屬性
<ANY [ng-form=""]> ... </ANY>as CSS class://做爲累,樣式
<ANY class="[ng-form: ;]"> ... </ANY>
Param | Type | Details |
---|---|---|
ngForm | name
(optional)
|
string |
表單的名稱,若是指定,控制器將發表形式到相關名字範圍,
|
<textarea ng-model="" [name=""] [required=""] [ng-required=""] [ng-minlength=""] [ng-maxlength=""] [ng-pattern=""] [ng-change=""] [ng-trim=""]> ... </textarea>
Param | Type | Details |
---|---|---|
ngModel | string | 可指定的angular數據綁定表達式 |
name
(optional)
|
string |
屬性名的形式控制發表。
|
required
(optional)
|
string | 若是你的值沒有鍵入,那麼設置 required 驗證錯誤的關鍵 |
ngRequired
(optional)
|
string |
添加所需的屬性,要求驗證約束元素ngRequired表達式的求值結果爲true。使用ngRequired而不是必需的當你想要數據綁定到所需的屬性。
|
ngMinlength
(optional)
|
number | 若是鍵入值比最短輸入值還少的話,設置的 minlength 就會生效提示錯誤 |
ngMaxlength
(optional)
|
number | 若是鍵入值比最短輸入值還多的話,設置的 maxlength 就會生效提示錯誤 |
ngPattern
(optional)
|
string | 若是不匹配正則,pattern 錯誤就會生效,預期值/正則表達式/內聯模式或者regexp模式定義爲範圍表達式。 |
ngChange
(optional)
|
string | Angular表達式被執行當輸入發生變化時因爲輸入用戶交互元素。 |
ngTrim
(optional)
|
boolean | 若是設置爲false Angular不會減小Input的輸入【減小兩遍的空格】 (default: true)--->默認爲true |
input控制着一下的一些HTML5表單類型以及對一個老版本的HTML5的驗證行爲。
ng-valid
,
ng-invalid
, ng-dirty
, ng-pristine
, ng-touched
, ng-untouched
)包括動畫。
<script> angular.module('inputExample', []) .controller('ExampleController', ['$scope', function($scope) { $scope.val = '1'; }]); </script> <style> .my-input { -webkit-transition:all linear 0.5s; transition:all linear 0.5s; background: transparent; } .my-input.ng-invalid { color:white; background: red; } </style> Update input to see transitions when valid/invalid. Integer is a valid value. <form name="testForm" ng-controller="ExampleController"> <input ng-model="val" ng-pattern="/^\d+$/" name="anim" class="my-input" /> </form>
<script> angular.module('changeExample', []) .controller('ExampleController', ['$scope', function($scope) { $scope.counter = 0; $scope.change = function() { $scope.counter++; }; }]); </script> <div ng-controller="ExampleController"> <input type="checkbox" ng-model="confirmed" ng-change="change()" id="ng-change-example1" /> <input type="checkbox" ng-model="confirmed" id="ng-change-example2" /> <label for="ng-change-example2">Confirmed</label><br /> <tt>debug = {{confirmed}}</tt><br/> <tt>counter = {{counter}}</tt><br/> </div>
ng-list=" | ".
input[select]
or input[radio],
因此當元素被選中selected的時候ngModel元素設置爲綁定值也就是value的值。
<script> angular.module('valueExample', []) .controller('ExampleController', ['$scope', function($scope) { $scope.names = ['pizza', 'unicorns', 'robots']; $scope.my = { favorite: 'unicorns' }; }]); </script> <form ng-controller="ExampleController"> <h2>Which is your favorite?</h2> <label ng-repeat="name in names" for="{{name}}"> {{name}} <input type="radio" ng-model="my.favorite" ng-value="name" id="{{name}}" name="favorite"> </label> <div>You chose {{my.favorite}}</div> </form>
Param | Type | Details |
---|---|---|
ngModelOptions | object |
選擇適用於當前的模型。有效值是:
updateOn :字符串指定應該輸入綁定到哪一個事件。你可使用一個空間分隔的列表設置幾個事件。有一個特殊事件
如今僅支持值是UTC,不然將使用瀏覽器的默認時區。
|
<ANY ng-bind=""> ... </ANY>
<ANY class="ng-bind: ;"> ... </ANY>
Param | Type | Details |
---|---|---|
ngBind | expression | 表達式來評估 |
<script> angular.module('bindExample', []) .controller('ExampleController', ['$scope', function($scope) { $scope.name = 'Whirled'; }]); </script> <div ng-controller="ExampleController"> Enter name: <input type="text" ng-model="name"><br> Hello <span ng-bind="name"></span>! </div>
<ANY ng-bind-template=""> ... </ANY>
Param | Type | Details |
---|---|---|
ngBindTemplate | string | 模板從 |
<script> angular.module('bindExample', []) .controller('ExampleController', ['$scope', function($scope) { $scope.salutation = 'Hello'; $scope.name = 'World'; }]); </script> <div ng-controller="ExampleController"> Salutation: <input type="text" ng-model="salutation"><br> Name: <input type="text" ng-model="name"><br> <pre ng-bind-template="{{salutation}} {{name}}!"></pre> </div>
<ANY ng-bind-html=""> ... </ANY>
Param | Type | Details |
---|---|---|
ngBindHtml | Expression | 解析表達式. |
<ANY ng-class=""> ... </ANY>as CSS class:
<ANY class="ng-class: ;"> ... </ANY>
ngClassOdd
and
ngClassEven 徹底按照ngclass來工做,
除了他們在一塊兒工做,
<ANY class="ng-class-odd: ;"> ... </ANY>
Param | Type | Details |
---|---|---|
ngClassOdd | expression |
表達式eval,結果能夠是一個字符串,用空格分割類或一個數組。
|