Angular show div基于URL参数

时间:2015-07-28 15:23:15

标签: html angularjs if-statement

有没有办法可以在Angular中显示基于URL参数的内容?

例如,myfile.php?id=123

<div ng-if="window.location.search.id != ''">
    Show content
</div>

1 个答案:

答案 0 :(得分:1)

在您的控制器/指令内部,您可以注入$location并使用它来检查查询参数

 angular
    .module('locationExample', [])
    .controller('ExampleController', 
     ['$scope', '$location', function($scope, $location) {
         $scope.search = $location.search();
     }]);


<div ng-if="$scope.search.id != ''">
    Show content
</div>
相关问题