0

I have some issues with angular. I have a directive with link function like this:

link : function(scope, element, attrs, ctrl) {
        element.bind("click", function(e) {
        $rootScope.$emit('FIELD-TYPE', {
            field_type : scope.field.field_type.valueOf()
        });
        });
    }

and another directive on a sibling scope

    $rootScope.$on('FIELD-TYPE', function(event, args) {
        scope.field_type = args.field_type;
        element.children().remove();
        var template = $templateCache.get('propertyBox');
        element.append(template);
        $compile(element.contents())(scope);
        });

so far the $emit gets captured and the content gets loaded. But in the content I have some bindings via ng-model. The values aren't sent over between the directives, they have other scopes, so ma question is.. How to setup the to way data binding between those scopes? or is my approach bad?

greets

S3B4ST14N
  • 65
  • 2
  • 7
  • can [this](http://stackoverflow.com/questions/13482351/sharing-data-between-directives) be helpful? – G-Host Mar 27 '15 at 08:52
  • not really, cause the first directive gets the scope with variables already set. If I bind the siblings scopes together with a service like u suggested, the scope one lever higher will lose the binding with the first directive. – S3B4ST14N Mar 27 '15 at 10:18
  • maybe i misunderstood the question, so the scenary is: a controller with two directives tied together with a $scope model variable. Is it the point? cause i would not use event broadcasting/emitting for such a situation, model drive is always better. watch this [fiddle](http://jsfiddle.net/xo858pv2/1/) tell me what you think. When you edit the scope model in any of controller/directive the value is rebounced everywhere – G-Host Mar 27 '15 at 11:10
  • you can see it better [here](http://jsfiddle.net/xo858pv2/2/) – G-Host Mar 27 '15 at 11:18

0 Answers0