A directive that renders in Angular

Angular interview exercise on Pipes & directives, difficulty 3 of 3. Solve it in the editor beside a worked example; the tests run the moment you do.

Write BadgeDirective, selector [appBadge], with a required `count` input (alias "appBadge"). While the count is above 0 it keeps a <span class="badge"> inside the host showing the count; at 0 the span is removed. InboxButtonComponent uses it on its button with the `unread` signal.

Each exercise pairs a worked example with a twin problem to solve in a real editor; the tests run the moment you do. Progress is saved in your browser, and in your account if you sign in.

More Pipes & directives in Angular

All Angular exercises · Other languages and frameworks