3

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>
1
  • 1
    Are you using ui-router ? Commented Jul 28, 2015 at 15:30

1 Answer 1

2

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>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.