2
votes

I'm new to Angular and I have the following problem.

I'm trying to create a component that can be active. I currently set it up so it detects if an attribute called active exists and sets its internal state accordingly.

<page active page-id="page-1"></page>

The problem emerged when I wanted to remove the active state. How should I go about it? Should I switch to css classes? Or maybe use a directive?

1
how about simply remove the attribute? Setting the attribute as TRUE/FALSE ? - Rebornix

1 Answers

0
votes

This seems a little 'hacky' but, first you need to get the element somehow and access the attribute Map directly and just remove it like,

HTML

<page active page-id="page-1" id="page_one"></page>

Dart

querySelector('#page_one').attributes.remove("active");

https://api.dartlang.org/apidocs/channels/be/dartdoc-viewer/dart:html.Element#id_attributes