0

Isolated scopes has been discussed a lot, but I couldn't find a similar case.

I am using Angular in a website where the views are generated in PHP.

I have this kind of example of HTML content:

<my-directive>
  <div ng-repeat="item in list"></div>
  <ul>
    <li>some information 1</li>
    <li>some information 2</li>
    <li>some information 3</li>
    <li>...</li>
  </ul>
</my-directive>

<my-directive>
  <div ng-repeat="item in list"></div>
  ... // similar stuffs
</my-directive>

The list in "ng-repeat" is created from the content in the "ul" element which are populated in PHP in my HTML view.

If I don't isolate the scope, the "list" object in all my directive is the one from the last one.

If I isolate the scope, I can't access the list object in my directive (for my ng-repeat).

Usually scopes are injected in the directives but I have a lot of data from my list, so I can't just leave it as a params in my directive declaration.

Is there a correct way to do that?

[Edit]

I did a codepen to illustrate this issue:

http://codepen.io/laurent-le-graverend/pen/gljIa?editors=101.

In the JS code, if you try to remove the line 19, you will see that the filters appear, BUT it has the data from the last directive.

Laurent
  • 977
  • 3
  • 13
  • 27
  • why can't you link your `list` in the scope declaration of your directive? – Sebastian May 08 '14 at 08:54
  • I did a codepen to illustrate this issue: http://codepen.io/laurent-le-graverend/pen/gljIa?editors=101. In the JS code, if you try to remove the line 19, you will see that the filters appear, BUT it has the data from the last directive. – Laurent May 09 '14 at 04:56
  • It is nt really clear what you are trying to achieve... – gkalpak May 09 '14 at 05:44
  • Trying to access the "list" object in the directive markup, which does not work if I isolate the scope as I need it. – Laurent May 09 '14 at 08:12
  • Where are trying to access the `list` object from ? Outside of the isolate scope ? – gkalpak May 09 '14 at 16:19
  • Yes, I finally could make it work by using the inheritance. I didn't saw it this way before but it seems fine, by using "scope: true". – Laurent May 12 '14 at 00:11
  • @Laurent : do you have any solution for this? I'm also blocked with the same. – JiniKJohny Jul 01 '15 at 07:09
  • @JayKay, setting `scope: true` in your directive will create a new scope inherited from the parent; you can then access it easily. – Laurent Jul 02 '15 at 10:38

0 Answers0