Save 45% for a limited time.

Get access to all courses and lessons on egghead today.

Autoplay

    Switch Between Angular States on a Trigger

    John LindquistJohn Lindquist

    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.

    angularAngular
    2 - 4
    Code

    Code

    Become a Member to view code

    You must be a Member to view code

    Access all courses and lessons, track your progress, gain confidence and expertise.

    Become a Member
    and unlock code for this lesson
    Transcript

    Transcript

    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. .

    Discuss

    Discuss