jadjoubran / laravel5-angular-material-starter

Get started with Laravel 5.3 and AngularJS (material)
https://laravel-angular.readme.io/
MIT License
1.66k stars 400 forks source link

Acceder a un function de una directive en angular #440

Closed developcreativo closed 7 years ago

developcreativo commented 7 years ago
class LikeifController {
    constructor(LikesService) {
        'ngInject';
        this.LikesService = LikesService;

    }

    isLike(stream_id, streams){
        this.LikesService.getLikes(stream_id).then((response) => {
             if (response.data.message == "Unliked") {

                 var elmn = angular.element(document.querySelector('#myDiv'));
                 elmn.empty();
                 response.data.$destroy();

             }else {
                 streams.likes.data.push(response.data);
             }
        });
    }

}

export function LikeifDirective() {
    return {

        controller: LikeifController,
        link: function(scope, element, attrs, controllers) {
            var cloneElement = null;
            var cloneScope = null;
            scope.$watch(
                attributes.bnGoodIf,
                function handleWatchChange(newValue, oldValue) {
                    if (cloneElement) {
                        cloneScope.$destroy();
                        cloneScope = null;
                        cloneElement.remove();
                        cloneElement = null;
                    }
                    if (newValue) {
                        cloneScope = scope.$new();
                        cloneElement = transclude(
                            cloneScope,
                            function injectClonedElement(clone) {
                                element.after(clone);
                            }
                        );
                    }
                }
            );

        }
    }
}

mi controller import { LikeifDirective } from '../../../directives/likeif/likeif.directive.js'; $onInit(){

    this.pagination = '';
    this.loading = false;
    this.comentario = "";
    //Functions likes
    this.likes = (stream_id, streams) => {
        LikeifController.isLike(); // ? 

        });
    }
}
jadjoubran commented 7 years ago

Hi @vdjkelly What's the error that you're getting?

jadjoubran commented 7 years ago

Feel free to re-open with more info!