angular js 使用$location问题整理

angular js 自带的$location方法十分强大,通过使用$location方法。我们能够获取到server的port、杂乱连接中的path()部分(/所包括的部分)。

例:

// given url http://example.com/#/some/path?foo=bar&baz=xoxo

var path = $location.path();

// => "/some/path"


可是在使用location之前,应该在文件的开头定义一下内容

/*

 * 定义angular js 调用$location方法 

 */

angular.module("hairApp",[],function($locationProvider){

    $locationProvider.html5Mode(true);

});

而且在controller中生命$location。

例:

angular.module('hairApp').controller('ProjectController', function($scope,$location,$http){})

【推广】 免费学中医,健康全家人
原文地址:https://www.cnblogs.com/zhchoutai/p/8664121.html