L
L
lebedyncrs2015-01-21 21:43:39
Angular
lebedyncrs, 2015-01-21 21:43:39

AngularJs Passing variable from directive to controller?

I wrote my autocompleter. The problem is that I do not know how to pass a variable to the controller.
I would like something like this.
The select-object attribute recorded the data that I selected (the string from the input) and then I could operate on the myVariableInControlle variable in my controller.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
T
TekVanDo, 2015-01-21
@lebedyncrs

Pass select-object as an attribute, inside the directive, if it is passed, write the value into it..

angular.module('myDirective, [])
.directive('myDirective', function() {
  return {
    restrict: 'E',
    scope: {
      selectObject: '='
    },
    link: function(scope, element, attrs, controllers) {
       scope.selectObject = 'Result value';
    };
});

<my-directive select-object="myVariableInControlle"></my-directive>

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question