Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 角度UI路由器新视图,相同URL_Javascript_Angularjs_Angular Ui - Fatal编程技术网

Javascript 角度UI路由器新视图,相同URL

Javascript 角度UI路由器新视图,相同URL,javascript,angularjs,angular-ui,Javascript,Angularjs,Angular Ui,我在Angular应用程序中定义了以下状态,我想知道是否可以将另一个状态的模板注入当前状态 在我下面的.catch()中,我有:$state.go('error404')将触发error404状态并将用户重定向到/404。然而,我希望用户停留在触发404的相同URL上,404模板只是被注入到页面中。(因此没有重定向)。这可能吗 .state('error404', { url: '/404', template: '<p style="color:white

我在Angular应用程序中定义了以下状态,我想知道是否可以将另一个状态的模板注入当前状态

在我下面的
.catch()
中,我有:
$state.go('error404')将触发error404状态并将用户重定向到/404。然而,我希望用户停留在触发404的相同URL上,404模板只是被注入到页面中。(因此没有重定向)。这可能吗

.state('error404', {
        url: '/404',
        template: '<p style="color:white;">404 NOT FOUND</p>'
    })

.state('publicUserProfile', {
        url: '/:username',
        templateUrl: 'views/public-profile.html',
        controller: 'publicProfileController',
        resolve: {
            userData: ['$http', 'API_URL', '$stateParams', '$state', function ($http, API_URL, $stateParams, $state) {
                return $http
                .get(API_URL + '/users/' + $stateParams.username)
                .catch(function () {
                    $state.go('error404'); <-- HERE
                })
            }]
        }
    });
.state('error404'{
url:“/404”,
模板:“

404未找到” }) .state('publicUserProfile'{ url:“/:用户名”, templateUrl:'views/public profile.html', 控制器:“publicProfileController”, 决心:{ 用户数据:['$http','API_URL','$stateParams','$state',函数($http,API_URL,$stateParams,$state){ 返回$http .get(API_URL++'/users/'+$stateParams.username) .catch(函数(){


$state.go('error404');在这种情况下,您应该删除
url
属性:

.state('error404', {
        template: '<p style="color:white;">404 NOT FOUND</p>'
    })
.state('error404'{
模板:“

404未找到” })


哇,我怎么会错过呢?谢谢!