Skip to content
This repository has been archived by the owner on Dec 8, 2023. It is now read-only.

Loosing Scope #16

Closed
littlemtravis opened this issue Jan 12, 2015 · 5 comments
Closed

Loosing Scope #16

littlemtravis opened this issue Jan 12, 2015 · 5 comments

Comments

@littlemtravis
Copy link

I have setup my template, nav-template, like below.

(function () {
    'use strict';

    var sample = angular.module('sample', []).directive('navTemplate', navTemplate);

    function navTemplate() {
        var directive = {
            restrict: 'E',
            templateUrl: 'directives/nav/nav.html',
            scope: {
                versionHref: '@'
            },
            transclude: true
        };

        return directive;
    }
})();
nav/nav.html
<div ng-multi-transclude-controller>

        <div ng-multi-transclude="nav-header"></div>

        <div ng-multi-transclude="nav-menu"></div>

        <div ng-multi-transclude="nav-footer">
            <div>{{versionHref}}</div>
        </div>

</div>

Works: the nav-version directive finds the hrefPath on the scope

<body ng-init="{hrefPath='package.json'}">
        <nav-template version-href="{{hrefPath}}"></nav-template>
</body>

Doesn't Work: the nav-version directive doesn't find the hrefPath on the scope. The scope gets moved into the $$childHead.

<body ng-init="{hrefPath='package.json'}">
        <nav-template version-href="{{hrefPath}}">
            <div name="nav-footer">
                <div>This overriding template.</div>
                <div>{{versionHref}}</div>
            </div>
        </nav-template>
</body>
@zachsnow
Copy link
Owner

Your multi-transcluded blocks are linked in the context in which they are defined, not in context into which they are "injected". So you should use hrefPath because that's in scope. This is similar to #8 but I think it's quite reasonable that this might be expected to work, since you can see version-href right there. I'll have a look, thanks!

@zachsnow
Copy link
Owner

Let me know if this works for you!

@littlemtravis
Copy link
Author

Take a look at this http://plnkr.co/edit/50JMsM?p=preview, don't know why I didn't write a plunk to begin with.

@zachsnow
Copy link
Owner

I've updated it to reflect the change I suggested above:

http://plnkr.co/edit/lv7AHh?p=preview

Hope that helps.

@littlemtravis
Copy link
Author

Got it, makes sense. Thanks for the help.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants