根据URL参数,在Angular中显示div

3

在Angular中,是否有一种方法可以根据存在URL参数来显示内容?

例如,myfile.php?id=123

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

1
你是否正在使用 ui-router - Razvan B.
1个回答

2

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

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


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

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接