⚠️ This lesson is retired and might contain outdated information.

Switch Between Angular States on a Trigger

John Lindquist
InstructorJohn Lindquist
Share this video with your friends

Social Share Links

Send Tweet
Published 8 years ago
Updated a month ago

Triggers work in combination with states to define ways of getting from one state to the next. This lesson covers how to create multiple states then cause the trigger assignment to update from one state to the next.

[00:00] Now we can add a second state, so just take this line and duplicate it. I'll call this state stop, and make the background color red. To get from go to stop I can come in here and change this to stop.

[00:15] Hit Save, and you'll see this change to red. But now instead of hard coating stop let's cut it out and make a property called signal here. We'll assign that. Now we can assign the trigger of signal to this property of signal, so that whenever this signal changes you'll see that we're still red, because it's just reading in the string of stop.

[00:38] Whenever the signal changes, the state will change. We'll put a button on there, this will be our go button, on, go, click. In our on, go, click method here we'll say this.signal is go. Now we start at stop, but when I click the go button, it changes screen because it's switching from the stop state to the go state. The background color in the go state is green. .

~ 6 years ago

Does this still work as is in ng5?

Markdown supported.
Become a member to join the discussionEnroll Today