源代码 :
点击运行
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <script src="https://cdn.staticfile.org/angular.js/1.4.6/angular.min.js"></script> </head> <body> <div ng-app="myApp" ng-controller="myCtrl"> <p> 当前页面的url:</p> <h3>{{myUrl}}</h3> </div> <p>该实例使用了内建的 $location 服务获取当前页面的 URL。</p> <script> var app = angular.module('myApp', []); app.controller('myCtrl', function($scope, $location) { $scope.myUrl = $location.absUrl(); }); </script> </body> </html>
运行结果