N
N
Nikolay2017-03-09 18:09:39
Angular
Nikolay, 2017-03-09 18:09:39

How to pass data from a controller to a directive?

Good evening)
Please tell me how (in the first angular) to pass a variable from the controller to the directive using the syntax controller as
For example:

angular
    .module('test', [])
    .controller('first', function () {
        this.somevar = 'Lorem';   // -> Эту переменную
    })
    .directive('one', function () {
        restrict: 'A',
        link: function () {
            console.log(somevar); // <- Получить здесь
        }
    });

Answer the question

In order to leave comments, you need to log in

1 answer(s)
N
Nikolai, 2017-03-09
@iNickolay

Something like:

angular
    .module('test', [])
    .controller('first', function ($scope) {
        $scope.somevar = 'Lorem';   // -> Эту переменную
    })
    .directive('one', function () {
        restrict: 'A',
        link: function (scope) {
            console.log(scope.somevar); // <- Получить здесь
        }
    });

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question