2

In a webpage that I am building I am using AngularJS ng-hide to show-hide an element(basically a button). But what it actually does is simply add a class ng-hide to that element.

So anybody can go to developer tools and remove the class ng-hide and the button will be visible. I know using jQuery I can completely remove the element from HTML but is there a way to do that in angular?

Before it looks like this:

<button ng-hide="hide">Button</button>

And after hiding it looks like:

<button class="ng-hide">Button</Button>

2 Answers 2

5

You are looking for ngIf.

The ngIf directive removes or recreates a portion of the DOM tree based on an {expression}. If the expression assigned to ngIf evaluates to a false value then the element is removed from the DOM, otherwise a clone of the element is reinserted into the DOM.

<label>Click me: <input type="checkbox" ng-model="checked" ng-init="checked=true" /></label><br/>
Show when checked:
<span ng-if="checked" class="animate-if">
  This is removed when the checkbox is unchecked.
</span>
Sign up to request clarification or add additional context in comments.

1 Comment

Never knew ng-if actually removes the element from DOM. Thanks.
0

This should work:

angular.element("button").remove();

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.