AngularJS 最常用的八种功能

第一 迭代输出之ng-repeat标签
<li ng-repeat=”person in persons”>
{{person.name}} is {{person.age}} years old.
</li>

第二 动态绑定之ng-model标签
<input type=”text” ng-model=’password’>

第三 绑定点击事件之ng-click事件
<button ng-click=”pressMe()”/>

第四 分支语句之ng-switch on、ng-if/ng-show/ng-hide/ng-disabled标签
<li ng-repeat=”person in persons”>
<span ng-switch on=”person.sex”>
<span ng-switch-when=”1″>you are a boy</span>
<span ng-switch-when=”2″>you are a girl</span>
</span>
<span ng-if=”person.sex==1″>you may be a father</span>
<span ng-show=”person.sex==2″>you may be a mother</span>
<span>
please input your baby’s name:<input type=”text” ng-disabled=”!person.hasBaby”/>
</span>
<span>
</li>

第五 校验语法之ng-trim ng-minlength ng-maxlength required ng-pattern 等标签
<form name=”yourForm”>
<input type=”text” name=”inputText” required ng-trim=”true” ng-model=”userNum” ng-pattern=”/^[0-9]*[1

-9][0-9]*$/” ng-maxlength=”6″ maxlength=”6″/>
</form>

第六 下拉框之ng-options标签
<select ng-model=”yourSelected” ng-options=”person.id as person.name in persons”></select>

第七  控制css之ng-style标签
<span ng-style=”myColor”>your color</span>
$scope.myColor={color:’blue’};
$scope.myColor={cursor: ‘pointer’,color:’blue’};

第八  异步请求之$http对象
$http({method : ‘POST’,params : { id:123}, data:{name:’john’,age:27}, url : “/mypath”})
.success(function(response, status, headers, config){
//do anything what you want;
})
.error(function(response, status, headers, config){
//do  anything what you want;
});