Using Jquery & Angular Hybrid

0

I have a question, I hope and you can help me. I have a jquery function that I am using in angular , it is to generate datatable ... the point is that inside the function I can not use router.navigate[enlace];

     $('#example tbody').on( 'click', '.btn-detalle', function fun () {           
       var data = tabla.row( $(this).parents('tr') ).data();
        var id = data[0];
        localStorage.setItem('actionId',id);
        this.router.navigate(['inicio/editUser']);
    }); 

This is the function that I would like to use; I do not use window.location.href(enlace) because it loses the reactive load.

I hope and you can guide me, greetings !!!!

    
asked by Xavi Morales 23.11.2018 в 01:18
source

1 answer

0

I found the error, to be able to use

this.router.navigate[(ruta)];

it is necessary to declare this in the following way

 decalre that=this;

that means that the code would be as follows

 that.router.navigate([ruta]);

means that it can already be used in this way:

$('#example tbody').on( 'click', '.btn-detalle', function () {
        var data = tabla.row( $(this).parents('tr') ).data();
        var id = data[0];
        localStorage.setItem('actionId',id);

        console.log(id);
        that.router.navigate(['inicio/editUser']);
    }); 
    
answered by 23.11.2018 в 20:57