0

Noticed strange thing, when I name directive scope parameter dataSource it always undefined.

Here is an example: http://plnkr.co/edit/F0wIVUTj9lavVZyFIxKn?p=preview

If you change dataSource to for example ds everything works.

Question: why?

1
  • And are you sure to use exactly scope: { dataSource: "=" } instead of scope: { dataSource: "&" }. controllerFunction is function not simple property. If you will change it dataSource will not be undefined edited sample. Commented Jan 14, 2016 at 12:37

1 Answer 1

3

As you can read here, angular normalizes all attributes, a standard prefix for attributes is data-. So when you name your attribute data-source, it will actually be bound to your directive as source

Your corrected fiddle code

Now can be accessed as $scope.source in your directive.

Sign up to request clarification or add additional context in comments.

Comments

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.