Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Angular show div based on URL parameter

Is there a way I can display content based on a URL parameter being present, in Angular?

For example, myfile.php?id=123

<div ng-if="window.location.search.id != ''">
    Show content
</div>
like image 673
Rob Avatar asked Feb 13 '26 18:02

Rob


1 Answers

Inside of your controller/directive you can inject $location and use it to check for query params

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


<div ng-if="$scope.search.id != ''">
    Show content
</div>
like image 187
Hacknightly Avatar answered Feb 15 '26 14:02

Hacknightly



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!