2015/10/02

AngularJS $location

$location是繼承於window.location



<!DOCTYPE html>
<html ng-app="myApp">
  <head>
    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/angularjs/1.4.3/angular.min.js"></script>
    <script type="text/javascript">
      var myApp = angular.module('myApp', []);
      myApp.controller('myController', function($scope, $location){
        $scope.location = $location;
      });
    </script>
    <meta charset="utf8"/> 
    <title>Filter</title>
  </head>
  <body ng-controller="myController">
    <div>
      <p ng-bind="location.absUrl()"></p>
      <p ng-bind="location.protocol()"></p>
      <p ng-bind="location.host()"></p>
      <p ng-bind="location.port()"></p>
      <p ng-bind="location.path()"></p>
    </div>
  </body>
</html>

執行結果: