N
N
neJa2014-06-11 15:17:12
JavaScript
neJa, 2014-06-11 15:17:12

Updating $scope via directive attribute value in AngularJS

Hello.
I'm not very familiar with Angular.
There is a custom directive, the path to the $scope that needs to be updated is passed as a value:

<div custom-directive="data.sliders[0].title"></div>

values ​​may be different.
Inside the directive, I want to use this directive value - "data.sliders[0].title" and update it in $scope:
.directive('customDirective', function() {
    return {
        link: function(scope, element, attrs) {
            // scope.data.sliders[0].title - это то, как должно работать, но через значение attrs.customDirective
            // scope.??
        }
    }
})

Thank you.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
maxaon, 2014-06-11
@neJa

directive('customDirective', function () {
    return {
        scope: {
            customDirective: '='
        },
        link: function (scope, element, attrs) {
            //scope.customDirective тут вы будете иметь доступ к значению из 'scope.data.sliders[0].title' 

        }
    };
})

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question