material icon indicating copy to clipboard operation
material copied to clipboard

md-item-template for md-autocomplete cannot access parent scope

Open 4storia opened this issue 11 years ago • 4 comments

This seems to be an issue that was introduced at some point in 0.11, as my upgrade to 0.11 from 0.10.1 seems to break things.

In short, I have a directive that essentially wraps md-autocomplete, and provides some app-specific logic that helps with the display of autocomplete items. It is still intended to be just as generic as md-autocomplete, but part of wrapping md-autocomplete means I would prefer to be able to abstract some of the templating logic for each item. I've added a codepen below to give some insight into this problem, but essentially what I'm doing is:

<div class="extended-autocomplete-directive">
    <md-autocomplete md-items="item in ...">
        <md-item-template>
            <div  class='template-text' >{{item[someDisplayAttributeAttachedToDirectiveScope]}}</div>
        </md-item-template>
    </md-autocomplete>
    <div class="some-other-stuff">...</div>
</div>

This worked in 10.1, and allowed me to attach an arbitrary attribute to the scope of my directive that I could use in my md-item-template to help display the information I wanted. This seems to no longer work in 11.0.

I've also tried using ng-transclude to pull in the md-item-template from further up. The markup would look like:

<extended-md-autocomplete>
    <md-item-template>
        ...
    </md-item-template>
</extended-md-autocomplete>

With my directive template looking something like:

<div class="extended-md-autocomplete">
    <md-autocomplete ng-transclude></md-transclude>
</div>

This throws a transclusion error (duh), as md-autocomplete does not transclude.

I'm thinking this is a bug, but maybe its intended behavior. If so, advice on how to proceed would be much appreciated.

Code pen: http://codepen.io/Flare/pen/KdpoeZ?editors=101

4storia avatar Sep 08 '15 17:09 4storia

This looks like a more generic version of bug #4390. I will investigate.

topherfangio avatar Sep 09 '15 16:09 topherfangio

@4storia Would you be able to test PR #4391 to see if it resolves your issue?

topherfangio avatar Sep 10 '15 15:09 topherfangio

Yes, this fixes my issue. Good stuff :D

4storia avatar Sep 11 '15 16:09 4storia

@4storia Awesome, thanks for the feedback!

topherfangio avatar Sep 11 '15 16:09 topherfangio