Search code examples
angularjsng-showng-hide

AngularJS hide div based on url/condition


This is my url - charts/53d25d91959679701e362f25 and when I add ?widget=true to that link charts/53d25d91959679701e362f25?widget=true I have to hide two particular divs in charts/53d25d91959679701e362f25 page.

I've tried - ng-if="location.path()" but is not working for ?widget=true


Solution

  • You cannot use $location service in ng-if directive

    User $location to set some scope and tie ng-if to that scope variable.

    if(angular.isDefined($location.search().widget)) {
         $scope.isHidden = true;
    } 
    else {
         $scope.isHidden = false;
    }
    
    ng-if="isHidden"