Become a member
to unlock all features

Level Up!

Access all courses & lessons on egghead today and lock-in your price for life.


    Switch Between Angular States on a Trigger

    2 - ~8.1.1

    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.



    Become a Member to view code

    You must be a Pro 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
    orLog In




    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.

    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.

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