1

How can I use an array which is given as an attribute of a directive in the linker of the directive

[
{
    "state": "bootstrap.formwizard.ethernet",
    "placeHolder": "lNetworkConfWizardMenu",
    "stepNumber": 1,
    "next": "bootstrap.formwizard.datetime"
},
{
    "state": "bootstrap.formwizard.datetime",
    "placeHolder": "lDateSetWizardMenu",
    "previous": "bootstrap.formwizard.ethernet",
    "stepNumber": 2,
    "next": "bootstrap.formwizard.countrysetting"
},
]

Template

<formprogressbar steps="wizardSteps"  />

Directive

angular.module('smaModules.formProgressbar', [])

.directive('formprogressbar', function ($log) {

    function linker(scope, element, attrs) {
        console.log(scope);
        test = attrs.steps[0]
        console.log(test);
    }


    return {
        restrict: 'E',
         scope: { 
             steps: '=' 
        },
        template: 'Steps: {{ steps[0] }}',
        link: linker
    };
});

In the template I have access but not in the linker function. What's wrong?

1 Answer 1

1

You want to access the steps off of your scope for it to be the same as in your template. Also you should declare your variable for best practice.

.directive('formprogressbar', function ($log, $filter) {

    function linker(scope, element, attrs) {
        console.log(scope);
        var test = scope.steps[0];
        console.log(test);
    }


    return {
        restrict: 'E',
         scope: { 
             steps: '=' 
        },
        template: 'Steps: {{ steps[0] }}',
        link: linker
    };
});

attrs.steps[0] was probably giving you the result of 'w', this is because attrs.steps is the string "wizardSteps", the first index of the string being 'w'.

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.