Exposing the current state name with ui router

前端 未结 6 1552
清歌不尽
清歌不尽 2020-12-14 05:28

I\'m trying to implement a language switcher where if a user clicks on \"de\" from any given page on an \"en\" side - it takes them to that page of the \"de\" side. If I con

6条回答
  •  半阙折子戏
    2020-12-14 06:07

    this is how I do it

    JAVASCRIPT:

    var module = angular.module('yourModuleName', ['ui.router']);
    
    module.run( ['$rootScope', '$state', '$stateParams',
                          function ($rootScope,   $state,   $stateParams) {
        $rootScope.$state = $state;
        $rootScope.$stateParams = $stateParams; 
    }
    ]);
    

    HTML:

          $state = {{$state.current.name}}
          $stateParams = {{$stateParams}}
          $state full url = {{ $state.$current.url.source }}    
    

    EXAMPLE

    http://plnkr.co/edit/LGMZnj?p=preview

提交回复
热议问题