Как использовать две директивы angular.js?

0

Я определил две директивы для подключения элементов dom на экране. Обе директивы прекрасно работают при использовании в качестве отдельных директив. Я пытаюсь использовать один директивный элемент в другой директиве, но пока не удалось. Вот мой код.

angular.module('mainModule').directive('createConnections', function($interval) {
    return {
        restrict: 'EA',
        link: function(scope, element, attrs) {

            element.connections({ from:'div.new-div' }).length;
            /*element.connections(attrs).length;*/
            var connections = angular.element('connection, inner');
            $interval(function() { connections.connections('update') }, 10);
        }
    };
});


angular.module('mainModule').directive('updateConnections', function($interval) {
    return {
        restrict: 'EA',

        link: function(scope, element, attrs) {


            element.connections({ from:'div.actor{{index}}' }).length;
            /*element.connections(attrs).length;*/
            var connections = angular.element('connection, inner');
            $interval(function() { connections.connections('update') }, 10);
        }
    };
});

Код шаблона:

 <div create-connections class="actor\{{$index}}" >

        <span><button class=" aui-button dialog-show-button-impact"  style="float: left" title="$i18n.getText('add.activity')"
                      id ="div.actor-\{{$index}}"  ng-click="addActivity(actor)"><span class="aui-icon aui-icon-small aui-iconfont-add">Add</span>
        </button>\{{actor}}</span>
    <br/>
</div>



 <div ng-repeat="activity in activities">



        <div  update-connections ng-if="actor == activity.id" style="margin-left: -45%;">

            <div class="actor\{{actors.indexOf(actor)}}">
            </div>


                <div  ng-repeat = "impact in activity.text" class="impact\{{$index}}" id="">

                    \{{impact}}</div>
            </div>

        </divupdate-connections>

 </div>

Я не могу подключить второй уровень элемента к соответствующему элементу родителей. Изображение 174551

2 ответа

0

добавлен атрибут внутри имени подключения к соединению actor-id.

обновил директиву, чтобы получить идентификатор attrs actor-id и связать его с элементом.

angular.module('mainModule').directive('updateConnections', function($interval) {
    return {
        restrict: 'EA',

        link: function(scope, element, attrs) {

            attrs.$observe('actorId', function(value) {
                console.log('actorId=', value);

               /* value =" '"+ "div." + value + "' ";
                console.log("Connection value:" + value)*/

                element.connections({ from: 'div.'+ value}).length;
                element.connections(attrs).length;
                var connections = angular.element('connection, inner');
                $interval(function() { connections.connections('update') }, 10);
            });


        }
    };
});
0

замените директиву createConnection

angular.module('mainModule').directive('createConnections', function($interval) {
return {
    restrict: 'EA',
    transclude:true,
    link: function(scope, element, attrs) {

        element.connections({ from:'div.new-div' }).length;
        /*element.connections(attrs).length;*/
        var connections = angular.element('connection, inner');
        $interval(function() { connections.connections('update') }, 10);
    },
    template:'<div ng-transclude></div>
};
});

Ещё вопросы

Сообщество Overcoder
Наверх
Меню