0

How can pass the variable itemSelect inside my directive to my controller?

mDirective.directive('directive', function() {
    return {
        restrict: 'A',
        scope: {
            options: "="
        },
        templateUrl: '',

        link: function(scope, element, attrs) {  
                .........               
             $(element).find('.typeY').on('change', function() {
                var itemSelect =   $(element).find('.typeY').val();
            });
        } ,

    };
});
1
  • You can explain more than that. Commented Jan 20, 2014 at 15:47

1 Answer 1

1

Something like

mDirective.directive('directive', function() {
    return {
        restrict: 'A',
        scope: {
            options: "=",
            selected:"=",
        },
        templateUrl: '',

        link: function(scope, element, attrs) {  
                .........               
            $(element).find('.typeY').on('change', function() {
                scope.$apply(function() {
                  scope.selected=value;  // value from the element
                });
            });
        } ,

    };
});

At html level

<div directive options='expression' selected='expressionToTheScopeProperty'/>

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.