Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

ng-show, ng-hide not working in directive template #2339

@OHB

Description

@OHB

Hello! I'm trying to make a reusable spinner directive so I can hide sections of the page with a spinner before data is loaded:

myModule.directive('spinner', function() {
    return {
        template: '<div ng-hide="{{variable}}">SPINNER!!!</div><div ng-show="{{variable}}" ng-transclude></div>',
        replace: false,
        transclude: true,
        controller: ['$scope', '$element', '$attrs', function($scope, $element, $attrs) {
            $scope.variable = $attrs.spinner;
        }]
    };
});

I attach it like this:

Angular turns it into:

<div ng-controller="careerStatsCtrl" class="sidebar ng-scope" spinner="careerStats">
    <div ng-hide="careerStats" style="">SPINNER!!!</div><div ng-show="careerStats" ng-transclude="" style="display: none;">
    <!--contents-->
    </div>
</div>

Show/Hide just doesn't work...and I know that careerStats is being set in the careerStatsCtrl controller. If I add the following in the html directly, it works:

<div ng-show="careerStats">SHOW</div><div ng-hide="careerStats">HIDE</div>

Anyone have an idea?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions