0

If I have a custom directive that has an attribute on it:

<my-directive data-value="myController.somePropertyOnAController"><my-d...>

Is there any difference at all between passing that property from the controller to the directive and using a function to pass that property to the directive as long as they both pass the same property value?

<my-directive data-value="myController.getSomePropertyOnAController()"><my-d...>

I was told today that dirty checking can't happen properly in the second case and I have not been able to find anything to that effect. I'm trying to understand why using a function would interfere here.

ialexander
  • 898
  • 10
  • 28
  • see this http://stackoverflow.com/questions/14050195/what-is-the-difference-between-and-in-directive-scope-in-angularjs – Hadi J Apr 17 '17 at 15:42
  • @HadiJeddizahed Thanks for the link Hadi, but I think my question is different. In both cases what is passed into the directive will be the same, and those symbols for describing the bindings of attributes really would not apply in this case. If I was passing a function instead of a function value I could understand what you mean. But to me in this case, its the exact same thing. Right? – ialexander Apr 17 '17 at 15:56
  • 1
    No it isn't correct. when you pass a function to property of directive that its type is string(i.e `@`) then that function interpret as string. I do not you get noticed i mean? – Hadi J Apr 17 '17 at 16:21
  • @HadiJeddizahed My point is that from inside that controller, value has the same value either way right? Its just a string. You are saying the inside the controller, myController.value does not have just a string value, but is an actual reference to the function instead? – ialexander Apr 17 '17 at 16:48
  • 1
    @HadiJeddizahed If you create an answer from your comment I would be happy to accept it as the answer. I thought that passing in myController.getSomePropertyOnAController() would be the same as passing in {{myController.getSomePropertyOnAController()}}, that only the value would be passed in. I understand now that its not passed by value. – ialexander Apr 18 '17 at 12:31

1 Answers1

1

The scope of directive have several type as below.

`@` Attribute string binding

`=` Two-way model binding

`&` Callback method binding

`<` One-way binding

when you pass a function to property of directive that its scope's type is string(i.e @) then that function interpret as string. for more information you can see this link

Community
  • 1
  • 1
Hadi J
  • 16,989
  • 4
  • 36
  • 62
  • Thanks. While I understand the various bindings, I misunderstood and thought that the return value of the function would be passed in instead of the function itself. – ialexander Apr 19 '17 at 14:37