Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • What is the difference between '@' and '=' in directive scope

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 555
    Comment on it

    '@' is used to send the property from parentScope to isolatedScope. By transfer, you are not able to change the property of parentScope that is being pass. It is called one-way binding.

    If the binding property is a primitive type, like interpolatedProp in the example: you can modify interpolatedProp, but parentProp1 from where the value is come would not be changed. However, if you change the value of parentProp1, interpolatedProp will be overwritten with the new value (when angular $digest).

    If the binding property is some object, like parentObj: since the one passed to isolatedScope is a reference, modifying the value will trigger this error:

    TypeError: Cannot assign to read only property 'x' of {"x":1,"y":2}
    

    And by using "=" is called two-way binding, which means any modification in childScope will also update the value in parentScope, and vice versa. This rule works for both primitives and objects. If you change the binding type of parentObj to be =, you will find that you can modify the value of parentObj.x.

    & allows the directive to call some parentScope function and pass in its parameters.

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: