zachsnow / ng-multi-transclude

ng-multi-transclude
MIT License
79 stars 19 forks source link

Feature Idea: mutli-transclusion lifecycle events #21

Open jusopi opened 9 years ago

jusopi commented 9 years ago

btw I wasn't sure how to mark this as a feature request rather than a bug

preface

I recently ran into an issue whereby I was trying to use a custom directive's link function to find transcluded content. Example in coffeescript:

nxSave directive
.directive 'nxSave', ($parse)->
    {
        restrict: 'A'
        link: ($scope, elem, attrs)->
            func = $parse(attrs.nxSave)

            elem.find('input').bind 'blur', ->
                func($scope)
    }

This is a view that makes use of my nx-panel directive which makes use of multi-transclude. Normally using nx-panel works fine elsewhere in my app. It just doesn't play well w. other custom directives.

some view
<nx-panel nx-save="onNxSave()">

    <label name="title">
        Transcluded Title
    </label>

    <div name="content">
        <p>Transcluded Content</p>
        <input type="text" ng-model="viewData.description"/>
        <input type="text" ng-model="viewData.other"/>
    </div>
</nx-panel>

issue

The problem is that regardless of where I place this directive within my existing multi-transcluding-directive (rather my directive that utilizes your library), it never finds said elements due to the fact that those elements are recompiled into the DOM afterwards. Changing priority doesn't work either.

possible solution

Ergo the suggestion for some sort of lifecycle events. This would be something that the multi-transclude-controller could dispatch after rendering the copied content into it's element. Then any view/directive that is listening for these events could possibly make use of them, such as in my case, trying to traverse the DOM and attach additional functionality.

This may also solve issues https://github.com/zachsnow/ng-multi-transclude/issues/14 & https://github.com/zachsnow/ng-multi-transclude/issues/18

zachsnow commented 9 years ago

Any chance you could concoct a working (well, broken) demo that includes the code to nx-panel and such? If there's directives you can't use because of multi-transclusion we should definitely find a workaround or proper fix. Cheers.

jusopi commented 9 years ago

@zachsnow Yes I could certainly do that. Give me a day or so. I can use plunker and gist so that you can test the code (I know debugging in Plunker can be a pain)

jusopi commented 9 years ago

Well I say this, but as I write up this demo in plunker I am unable to recreate the issue I was having. It may be that your fixes for the other recent issues has fixed that or I have invariably corrected a problem in my code that was completely unrelated to your directive. I will post back when I have something more.

zachsnow commented 9 years ago

@jusopi there were definitely some significant issues that were resolved with the last commit. Hopefully that was it!