How can I modify angularjs transcluded element?

Viewed 33

I have parent-directive and child-directive. I'm using ng-transculde.

<parent-directive>
    <child-directive type="SOME_TYPE" 
                     class="child"
                     options="{fooId: vm.fooId, fooType: vm.fooType}">
    </child-directive>
</parent-directive>

I want to set child-directive "id" from parent directive. Now I'm trying to do like this:

.directive('parentDirective', function ($rootScope, fileService) {
        return {
            transclude: true,
            restrict: 'E',
            scope: {
                disabled: "=?"
            },
            link: function (scope, element, attrs) {
                document.getElementById('transcluded_content').firstElementChild.id = 'myId'
            },
            template: '<div><ng-transclude id="transcluded_content"></ng-transclude></div>'
        };
    })

It shows error TypeError: Cannot set properties of null (setting 'id') I tried many ways and everytime it shows errors. I think I don't understand logic or I don't know method to use. Please help me...

0 Answers
Related