0

I want to pass argument to directive in angularjs.

I found some thread on stackoverflow Angularjs - Pass argument to directive

But it is not helped me.

Directive:

app.directive('datePicker', function () {
    return {
        restrict: 'E',
        replace: true,
        template: '<input type="text" class="form-control" ng-model="modelValue">',
        scope: {
            modelValue: '=',
            format: '@',
        },
        link: function (scope, element, form) {
            $(element).datepicker({
                dateFormat: format,
            });
        }
    }
})

Element:

<date-picker model-value="salary.month" format='MM-YYYY'></date-picker>

Here I want to use format as attribute to pass directive, So I can use same date-picker directive with different format.

I have tried with above code example,model value is working but format is not working.

Please help me to find solution

1 Answer 1

3

You should use scope.format to retrieve the value of the format attribute

link: function (scope, element, form) {
    $(element).datepicker({
        dateFormat: scope.format,
    });
}
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.