0

I have the following Angular directive:

var OrgChartDirective = function() {
    return {
        restrict: 'AE',
        scope: {
            source     : '=',
            container  : '=',
            stack      : '=',
            depth      : '=',
            interactive: '=',
            showLevels : '=',
            clicked    : '=' // We use '=' here rather than '&' for this callback function
        },
        link: function(scope, element, attrs) {
            var target = $(element);
            var source = $('#' + scope.source);
            var options = {
                container  : target,
                nodeClicked: scope.clicked,
                stack      : scope.stack,
                depth      : scope.depth,
                interactive: scope.interactive,
                showLevels : scope.showLevels
            };
            console.log("Drawing org chart at " + scope.source + " on " + target);
            console.log(scope);
            source.orgChart(options);
        }
    }
};

I add it to the page like:

<org-chart source='list-for-wf'/> or <div org-chart source='list-for-wf'> </div>

Problem is, in my console, I see:

Drawing org chart at 0 on [object Object]

Why is the source returning 0, this is like jquery when you try to access an invalid element. Even if I log the source as the first line of the link function it is 0

Why is that? I have tried data-source="..." and all kinds of stuff. Any ideas?

3
  • 2
    Could you try changing source: '=' to source: '@' Commented Feb 3, 2016 at 13:29
  • This works as well, thanks! Commented Feb 3, 2016 at 13:46
  • Implication of changing '=' to '@' is that you are happy for your source to be bound 1 way only. Commented Feb 3, 2016 at 13:50

1 Answer 1

3

Attributes are read as javascript expressions, so source="list-for-wf" is being interpreted as "the variable list minus the keyword for minus the variable wf". (I'm a bit surprised Angular doesn't throw an error on that keyword instead of returning zero, but hey.)

I think you want a quoted string instead: <org-chart source="'list-for-wf'">

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.