仅使用url参数ui-router重新加载嵌套状态而不是父级

时间:2021-10-24 11:43:40

I have a state and a nested state in my app.js file. The parent state has a button that controls what is viewed in the nested state, this is done by setting url parameter and the nested state's controller figures out what to show. I want to reload JUST the nested state when the user clicks the button.

我的app.js文件中有状态和嵌套状态。父状态有一个控制在嵌套状态下查看内容的按钮,这是通过设置url参数和嵌套状态的控制器确定要显示的内容来完成的。我想在用户单击按钮时重新加载嵌套状态。

I have both the parent state and the state I want to be reloading now on click.

我有父状态和我想在点击时立即重新加载的状态。

I found this * but the button being click is on the same page as the view being reloaded.

我发现了这个*,但是单击的按钮与正在重新加载的视图位于同一页面上。

App.js file

.state('index.main', {
    url: 'main/:userID',
    templateUrl: 'views/main.html',
    controller: 'MainCtrl'
})
.state('index.main.user', {
    url: '/',
    views: {
        'user@index' : {
            templateUrl: 'views/user.html',
            controller: 'UserCtrl'
        }
    }
})

Parent Controller

$scope.showUser = function(user) {
    $state.go('index.main.user', { userID: user._id });
}

1 个解决方案

#1


0  

Naturally right after I posted this question I found the exact answer I was looking for.

当我发布这个问题后,我发现了我正在寻找的确切答案。

This * helped me alot. I ended up using the following

这个*帮了我很多。我最终使用了以下内容

$state.go('index.main.user', { userID: user._id }, {reload: 'index.main.user');

#1


0  

Naturally right after I posted this question I found the exact answer I was looking for.

当我发布这个问题后,我发现了我正在寻找的确切答案。

This * helped me alot. I ended up using the following

这个*帮了我很多。我最终使用了以下内容

$state.go('index.main.user', { userID: user._id }, {reload: 'index.main.user');