I want to use ngClass to add a class to an element if another element exists in the DOM.
<div id="element-a"
[ngClass]="{'my-class':(expression-to-check-if-#element-b-exists)}">
...
</div>
<div id="element-b">I'm here!</div>
Is this possible to do directly in the template, or do I need to something more complex in the component?
You need to do more something in the component. It is not complex, just one line of code.
I will update this answer with more complex options if this doesn't suit your original need.