在 Angular 中,有没有一种方法可以根据存在的 URL 参数显示内容?
例如,myfile.php?id=123
<div ng-if="window.location.search.id != ''">
Show content
</div>
最佳答案
在你的 Controller /指令中你可以注入(inject) $location并用它来检查查询参数
angular
.module('locationExample', [])
.controller('ExampleController',
['$scope', '$location', function($scope, $location) {
$scope.search = $location.search();
}]);
<div ng-if="$scope.search.id != ''">
Show content
</div>
关于html - 基于 URL 参数的 Angular 显示 div,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31680695/