0

I study AngularJS directives at this link: Directives

When i reached the last example about: Creating Directives that Communicate

I did find this line(from script.js):

title: '@' // Line 33 at the script.js

The problem is that i don't know what this line means, I do know that title is an isolated scope property but what is the @, I have learned that:

  • '=' is where the attribute name is the same as the value
  • '=info' where info is the attribute

But the documentation from the link above is not explaining what is the @, My best guess is that when the @ is the value, The value assigned to the title property is the value from the title attribute, But i am not so sure if anyone can help me understand what it is i will be very thankful, Thank you all and have a nice day.

2
  • egghead.io/lessons here is thing that is better documentation. See video about @ parameter. Commented Jan 25, 2014 at 15:11
  • Thank you for the site Rantiev. Commented Jan 25, 2014 at 15:52

1 Answer 1

4

@ is a type of isolated scope binding (like =). However, @ says to only take the value of the attribute and not create a two-way bind to the outer scope.

So, if you wanted to use some value in the directive, but this value did not change for the duration of that instance of the directive, then @ is a good choice.

A quick example would be if you wanted to set a color for a directive template:

<my-color-box color="red"></my-color-box>

Then, in the directive you use the attribute like this:

app.directive('myColorBox', function() {

   return {
      restrict: E,
      scope: {
         color: '@'
      },
      template: '<div style="background-color: {{color}}"></div>'
   }
});
Sign up to request clarification or add additional context in comments.

2 Comments

Thank you Davin, I think i got it now.
Can be tricky at first to understand, but once you start using them it will make sense.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.