AngularJS UI Router $state reload child state only

后端 未结 4 1101
囚心锁ツ
囚心锁ツ 2020-12-05 13:42

I am using UI router for tabs of a main menu as well as for links within one of the states (users). The users state has a list of users and when a user is clicked, I want t

4条回答
  •  死守一世寂寞
    2020-12-05 13:54

    I have gotten it to work. I used what Radim suggested, but I had to add the url element to the state.

    .state('users.userGroups', {
        url: '/userGroups/{userTrigger}',
        templateUrl: '/User/UserGroups',
        controller: 'UserGroupController as userGroupCtrl'
    })
    

    and in my controller, when a user clickes on a link, I use the $state.transitionTo:

    var params = angular.copy($state.params);
    params.userTrigger = params.userTrigger === null ? "" : null;
    $state.transitionTo($state.current, params, { reload: false, inherit: true, notify: true }); 
    

    Just an FYI for any other newbies out there:

    after I added the url to the .state, I started having issues with my api calls. It was prepending the urls to the api methods with the url in my .state. You just have to be sure to have a leading / in your api urls:

    .factory('usersInGroup', function($http) {
        return {
            get: function(groupName) {
                return $http.get('/api/UserApi/GetInGroup/' + groupName);
            }
        }
    

    I saw and learned some pretty interesting stuff trying to muddle through this...

提交回复
热议问题