Angularjs $ routeparams和$ location之间的区别

时间:2015-07-31 00:02:01

标签: javascript angularjs

app.controller('GetData', function ($scope, $location, $routeParams)
{
var searchObject = $location.search();  
$scope.isActiveFromLocation = (searchObject.state == "active");      
$scope.isActiveFromRoute = ($routeParams.state == "active"); 
}

在上面的代码中,我试图通过angularjs从url querystring www.testsite.com/#xyz?state=active获取数据。我调试并发现两个范围变量都显示相同的结果。在这种情况下哪个选项最好读取查询字符串值?有什么建议。

0 个答案:

没有答案