<ul>
    <li ng-repeat="char in 
    [{'alphabet': 'K'},
    {'alphabet': 'A'},
    {'alphabet': 'V'},
    {'alphabet': 'L'},
    {'alphabet': 'E'},
    {'alphabet': 'Z'}] " ng-show="$even">{{char.alphabet}}</li>
</ul>
ng-href
起初我在一个文本域中弄了个ng-model,然后像这样<a href="https://www.jb51.net/{{myUrl}}">在href里面写了进去。
其实这样href和ng-href看不出什么区别,所以我们可以试试这样:
复制代码 代码如下:
<ul ng-init="myHref=''">
    <li><a ng-href="{{ myHref }}">{{linkText}}</a></li>
    <li><a href="{{ myHref }}">可以点击,但不一定是正确的地址</a></li>
</ul>
.run(function($rootScope, $timeout) {
    $rootScope.linkText = '尚未加载,您无法点击';
    $timeout(function() {
        $rootScope.linkText = '请点击'
        $rootScope.myHref = 'http://google.com';
    }, 2000);
})
ng-src
大同小异,即表达式生效前不要加载该资源。
例子(ps: 图片不错! ):
复制代码 代码如下:
<img ng-src="{{imgSrc}}"/>
.run(function($rootScope, $timeout) {
    $timeout(function() {
        $rootScope.imgSrc = 'https://octodex.github.com/images/daftpunktocat-guy.gif';
    }, 2000);
})
ng-class
用作用域中的对象动态改变类样式,例如:
复制代码 代码如下:
<style>
    .red {background-color: red;}
    .blue {background-color: blue;}
</style>
<div ng-controller="CurTimeController">
    <button ng-click="getCurrentSecond()" >Get Time!</button>
    <p ng-class="{red: x%2==0,blue: x%2!=0}" >Number is: {{ x }}</p>
</div>
.controller('CurTimeController', function($scope) {
    $scope.getCurrentSecond = function() {
        $scope.x = new Date().getSeconds();
    };
})  
