A
A
Artem00712017-02-04 14:56:38
Angular
Artem0071, 2017-02-04 14:56:38

How to convert directive from AngularJS to Angular 2?

There was a directive:

app.directive( 'vkComments', [
    '$window',
    '$timeout',
    function( $window, $timeout ){
        return {
            restrict: 'E',
            template: '<div id="vk_comments" ng-transclude post-url="{{url}}"></div>',
            scope: {
                readyToBind: '@'
            },
            replace: !0,
            transclude: !0,
            link: function( $scope, $element, $attr){
                $scope.$watch( 'readyToBind', function(){
                    $timeout( function(){
                        $window.vkComment = VK.Widgets.Comments( 'vk_comments', { limit: 10, attach: '*', autoPublish: 1, mini: 1 }, location.href);
                    }, 100 );
                } );
            }
        }
    }
] );

How to convert it into a component in Angular2, or is it better to convert it into a service altogether?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
Roman, 2017-02-24
@uaKorona

And what is the difficulty?
See the component specification in Angular 2 and redo it.
Along the way, get rid of any weird code like "transclude: !0,"

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question