夺命雷公狗—angularjs—14—$location的作用
废话不多说看下,我们直接来走代码看下效果如何
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Title</title> <script src="js/angular.min.js"></script> </head> <body ng-app="myapp"> <div ng-controller="app"> <p>protocol-----{{protocol}}</p> <p>absUrl-----{{absUrl}}</p> <p>-----{{port}}</p> <p>port-----{{path}}</p> <p>search-----{{search}}</p> <p>search2-----{{search2}}</p> <p>search3-----{{search3}}</p> </div> </body> <script> var app = angular.module('myapp',[]); app.controller('app',function($scope,$location){ $scope.protocol = $location.protocol(); $scope.absUrl = $location.absUrl(); $scope.port = $location.port(); $scope.path = $location.path(); $scope.hash = $location.hash(); $scope.search = $location.search(); //$scope.search2 = $location.search("user=admin&pass=passwd"); $scope.search3 = $location.search({"usera":"admin","userpass":"admin123"}); }); </script> </html>
最终效果如下所示: