angularjs directive hide element

Create a directive in app.js like below code:


app.directive('hideElement', function() {
     return function(scope, element, attrs) {
           element.hide();
     }
});


and use in your html page like

<a href="/#employees" hide-element>Employees</a>

You can also inject any service in this directive like:

app.directive('hideElement', function(EmployeeService) {
     return function(scope, element, attrs) {
         // Get data using employee service
         // and hide element according to any condition

           element.hide();
     }
});

No comments:

Post a Comment