Hello I am new at Angular,
Can I change variable from false to true by clicking a button?
I tried with event binding:
<button (click)=“setToTrue()”>CLICK
But variable is reset when the page is reloaded .
Is there a similar way to do this?
Hello I am new at Angular,
Can I change variable from false to true by clicking a button?
I tried with event binding:
<button (click)=“setToTrue()”>CLICK
But variable is reset when the page is reloaded .
Is there a similar way to do this?
These types of variables are expected to be reset when the page is loaded. When working with real-world applications, you will have a backend to store stable fields (where the button triggers changes to backend storage systems). In a course like Mosh’s, we are faking out backends (for the most part) and that does mean that the system resets whenever the page is reloaded (by design).
What you have written looks like it would work just fine (depending on how setToTrue()
is implemented), although you should probably use better function names (you will quickly find that names like that start begging the question “set what to true?”