[url={{myUrl}}]
其实这样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);
})
[b]ng-src
[/b]
大同小异,即表达式生效前不要加载该资源。
例子(ps: 图片不错! ):
<img ng-src="{{imgSrc}}"/>
.run(function($rootScope, $timeout) {
$timeout(function() {
$rootScope.imgSrc = 'https://octodex.github.com/images/daftpunktocat-guy.gif';
}, 2000);
})
[b]ng-class[/b]
用作用域中的对象动态改变类样式,例如:
<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();
};
})
以上就是本文所述的全部内容了,希望大家能够喜欢。