I often use ngRepeat to add multiple instances of a directive. For example,
<div ng-repeat="obj in list">
<div my-directive></div>
</div>
Inside of myDirective
, obj
is available via the scope. Then in the directive's template I can display some data.
<div>{{obj.someText}}</div>
This works great until I want to use that directive in multiple places. Then I realize that I've implicitly defined an interface for myDirective
: the data must be passed into the scope as an object named obj
. It doesn't feel right. It feels accidental. It's not clearly documented.
Is there any way around this?
The only way to avoid this that I could think of is worse. It would be to iterate over the keys in the scope and looking for values which don't start with $
. But if you find more than one key then you're hosed.
Perhaps my entire approach for passing data is just wrong.