Having a global state (or "mode") in my Angular Components is leading me to look for more efficient ways to code. Here is what I have tried:
@Component({
....
})
export class AbcComponent implements OnInit {
enum State {
init, view, edit, create, wait
}
state: State = State.init;
The concept here is that functions within AbcComponent can control the template's operations by simply setting the state property. For example:
<div class="col" *ngIf="state === State.view"> ... </div>
The issue arises when trying to define the enum inside the class structure, as it is not possible. Moving it outside means the template lacks access due to scope limitations.
Any suggestions on alternative methods to achieve this?
P.S. As a side note, I've experimented with using separate boolean properties for each state, such as modeInit, modeView, etc. It works but becomes cumbersome since only one should be set to true at any given time.