This Lesson is for Members

Subscribe today and get access to all lessons! Plus direct HD download for offline use, enhances transcripts, member comment forums, and iTunes "podcast" RSS feed. Level up your skills now!

Unlock This Lesson

Already subscribed? Sign In

Autoplay
    This lesson is outdated. Click here to find out about changes you should be aware of.

    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.

    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

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

    Discuss

    Discuss