I think it would be worth it to take a look at “Thinking in AngularJS” if I have a jQuery background?
However, to answer your question,
- I created an example PLNKR
- It answers your original question, before you changed it to checking if the element's child has the class.
- However, the same principles apply, so I'll provide my answer.
- It is worth noting that it's probably better practice to accomplish this using a directive.
- EDIT: I'd also like to second @charlietfl's comment. I think you may be approaching this issue backwards.
That being said, here is one solution:
HTML
<!-- remove 'active' from class, and element is no longer shown -->
<div id="special" ng-show="showElem" class="active">ACTIVE</div>
JS (Controller)
// get the element we want to test
var elem = angular.element(document.querySelector('#special'));
// check if that element has the class 'active'
$scope.showElem = elem.hasClass('active'); // true or false
Another way to do it would be:
<div id="special" ng-show="elem.hasClass('active');" class="active">ACTIVE</div>
and
$scope.elem = angular.element(document.querySelector('#special'));
Resources
- AngularJS documentation for:
- Relevant SO Questions