angularjs中的ng-src和ng-href
ng-src和ng-href等同于html中的src和href,只是ng是在dom加载完毕之后才能够发挥作用,如果在src或href中绑定变量,如果ng没有加载完,会导致链接地址出错,如果用对应的ng-src或ng-href,则不会出现这个问题。下面是一段示例代码:
<!DOCTYPE html> <html ng-app="myApp"> <head> <meta charset="UTF-8"> <title>interval</title> <script type="text/javascript" src="angular.min.js" charset="utf-8"></script> </head> <body ng-controller="ctrl"> <div><a ng-href="NewFile3_{{i}}.htm">链接</a></div> <div><input type="button" ng-click="clickEvent(1)" value="切换链接1" /><input type="button" ng-click="clickEvent(2)" value="切换链接2" /><input type="button" ng-click="clickEvent(3)" value="切换链接3" /></div> <script type="text/javascript"> var myApp = angular.module('myApp',[]); myApp.controller('ctrl', function($scope){ $scope.i = 1; $scope.clickEvent = function(index) { $scope.i = index; } }); </script> </body> </html>