// 带#号的url,看?号的url,见下面
url = http://qiaole.sinaapp.com?#name=cccccc

$location.absUrl();
// http://qiaole.sinaapp.com?#name=cccccc

$location.host();
// qiaole.sinaapp.com

$location.port();
// 80

$location.protocol();
// http

$location.url();
// ?#name=cccccc

// 获取url参数
$location.search().name;
// or
$location.search()['name'];

// 注:如果是这样的地址:http://qiaole.sinaapp.com?name=cccccc

var searchApp = angular.module('searchApp', []);
searchApp.config(['$locationProvider', function($locationProvider) {
  $locationProvider.html5Mode(true);
}]);
searchApp.controller('MainCtrl', ['$scope', '$location', function($scope, $location) {
  if ($location.search().keyword) {
    $scope.keyword = $location.search().keyword;
  }
}]);

 

点击查看DEMO

http://each.sinaapp.com/search/unicom.html?keyword=%E6%B5%81%E9%87%8F

 

 

 

若有疑问,请发表评论或添加微信为你解答:

【更新】AngularJs $location获取url参数

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-11-20
  • 2021-11-20
  • 2021-11-20
猜你喜欢
  • 2022-12-23
  • 2021-10-01
  • 2021-08-02
  • 2021-06-14
  • 2022-01-26
  • 2021-12-26
  • 2021-09-17
相关资源
相似解决方案