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

    New in Angular 1.4 - New bindToController Syntax

    John LindquistJohn Lindquist

    Angular 1.4 introduces a new syntax for bindToController. John demonstrates how to use it and what the new options are.

    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 When you set bindToController as true on your directive, if you pass a message into your scope, it's actually going to take that message and put it onto the controller as instance. Body, a body message, or, here, the body as and then the message coming in from the scope. You can see we have the message in our HTML. That's what's going to get passed in.

    00:24 In 1.4, if I swap this from the scope down to the bindToController, then I'll just type "true" here in the scope. This will actually achieve the exact same thing. If I just change my message to something like "New syntax," then you can see it changes to "New syntax" in the result.

    00:50 What this allows you to do is to change the scope as well to an object that can take a separate set of attributes and pass them in. You see I have a note here. I'll just go ahead and add a note in the HTML. Pass in "Hello." Then I can just show note inside of my template. When I save and refresh, you can see it says, "New syntax Hello."

    01:18 Honestly, I can't really think of a scenario where I'd use both the scope and bindToController as these objects, but I do like bindToController being an object that can take those different attributes because it expresses the intent of what I'm trying to do better.

    01:32 The only gotcha here is that if you don't include either the object or scope is true, then it's not going to assign those properties to the controller at all.

    Discuss

    Discuss