Home » Javascript » dynamic ui-sref in html does not run, runs href tag

dynamic ui-sref in html does not run, runs href tag

Posted by: admin November 1, 2017 Leave a comment

Questions:

I am consuming a web service before navigating to a controller. and here I GET a web request and the result of this request I keep it in the variable $rootScope.userSesion .This web service I want to run it every time I navigate to another view so I do not have to put the same code on each controller. :

angularRoutingApp.run(function($rootScope, $http){
    // this code is executed every time I change the view
    $transitions.onStart({ }, trans => {
    . 
    .
    .
    $rootScope.userSesion="gestionarUsuarios";
    })
    .
    .
    .
})

in the html view I’m putting my $rootScope.userSesion variable. when inspecting the element to which I want to click and that sends me to the state that I put in the ui-sref, does nothing and redirects me to another state(‘gestionarUsuarios’). the href tag attribute corresponds to the url of my current view.

enter image description here

when I click I should go to the “manageUsers” state but nothing happens. This is the code of my view.

<a class="columna_menu border_contenedor_seis" ui-sref="{{userSesion.estado}}">
 <div class="welle welle_seis"></div>

I want it when I click on the element to which I change the *ui-sref** allow me to navigate normally.

Answers:

It is hard to debug this issue from 3 lines of code, but as variable userSesion is a type string, your ui-sref should look like ui-sref="{{ userSesion }}.estado"