In AngularJS you can create your own services or use built-in services.
AngularJS Service syntax
In AngularJS, a service is a function or object that can be used in your AngularJS application.
AngularJS has more than 30 built-in services.
There is a $location service, which can return the URL address of the current page.
AngularJS Service example
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <script src="https://cdn.bootcss.com/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>
Run instance »
Click the "Run instance" button to view the online instance