M
M
Mike Diam2016-06-30 10:52:49
Angular
Mike Diam, 2016-06-30 10:52:49

How to pass data from directive to parent scope?

{{event}} Contains json with event data that needs to be passed to the parent scope in $scope.chEvent, but this does not happen, apparently the fancybox directive has its own isolated scope. How to solve the problem?

<div class="eve_cp" ng-repeat="event in events | filterBy:['type']:'main'">
                <img ng-src="{{event.image}}" ng-click="openFancybox('#viewEvent')" fancybox event='{{event}}'>
</div>
// Контроллер:

    .directive('fancybox', function ($compile, $http) {
        return {
            scope: true,
            restrict: 'EA',

            link: function(scope, element, attrs) {
                scope.openFancybox = function (href) {
                    //scope.chEvent.event = angular.fromJson(attrs.event)};
                    //console.log(scope.chEvent);

                    var template = angular.element(href);
                    var compiledTemplate = $compile(template);
                    compiledTemplate(scope);
                    $.fancybox.open();
                    $.fancybox.open({ href: href, type: 'inline' });
                    
                };
            }
        };
    })

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question