Become a member
to unlock all features

Level Up!

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


    Isolate Scope Change

    Unit Testing Directive Scope Binding

    John LindquistJohn Lindquist

    Digging a little deeper into unit testing an AngularJS directive, this lesson looks at testing binding across multiple scopes.



    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




    John Lindquist: If we want to bind some data between our parent scope and the directive scope. Let's set up some data on the scope. We'll have this have a property of message, which will just be "Hello." Then, we'll test to see if we can get these to both equal hello world. We'll say, should, update both scopes on click. We'll expect the scope and we'll just bind directly to S Simple message to be "Hello world."

    This will make more sense in just a second. The say scope data message to be "Hello world." Scope data message right now is just hello. Scope data message is hello and then we'll want to bind this add simple. We'll set up a two way binding, which is going to take the data in and set it here so that once we click.

    We say as simple message plus equals space world, then we should get those to pass because now the elements scope, the isolated scope where S simple is bound directly to data. Then we update this that should send the binding back to the root scope which means that this guy will also update.

    Both of these will update and equal hello world. So that's how you can test that your communication is working between your directive and parent scopes...