第一 迭代输出之ng-repeat
<ul>
<li ng-repeat="person in persons">
{{person.name}} is {{person.age}} years old.
</li>
</ul>
甚至可以以某个属性作为排序标准输出
<li ng-repeat="person in persons | orderBy:'name'">
第二 动态绑定之ng-model
任何有用户输入,只要是有值的html标签,都可以动态绑定js中的变量
<input type="text" ng-model='password'>
{{}}直接引用
<span>you input password is {{password}}</span>
filter过滤器
<span>{{1288323623006 | date:'yyyy-MM-dd HH:mm:ss Z'}}</span>
第三 绑定点击事件之ng-click
<button ng-click="pressMe()"/>
也可以传递一个对象
<ul>
<li ng-repeat="person in persons">
<button ng-click="printf(person)"/>
</li>
</ul>
第四 分支语句之ng-switch on、ng-if/ng-show/ng-hide/ng-disabled标签
<ul> <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> </ul>
第五 校验语法之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
如果是POST请求,params里的数据会帮你拼到url后面,data里的数据会放到请求体中$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; });