美元的状态.Go似乎不起作用

$state.go doesn't seems to be working

本文关键字:不起作用 Go 状态 美元      更新时间:2023-09-26

我有一个场景,当点击搜索项目时,我需要加载不同的状态

这是我的html代码

<span class="item-title" ng-click="fnViewProfile()">
      <span> {{item.name}} </span>
</span>
下面是我的控制器代码:
$scope.fnViewProfile = function() {
        $state.go("ViewProfile", {
            "id": 10215
        });
    }

在我的app.js中,我有一个解析函数,在那里我做了ajax调用,以便在html加载之前获取数据

.state('ViewProfile', {
            parent: 'home',
            url: '/ViewProfile:id',
            templateUrl: 'views/ViewProfileView.html',
            controller: 'ProfileViewCtrl',
            resolve: {
                profile: function(DashboardService, $stateParams, $scope) {
                    debugger;
                    var userId = $stateParams.id;
                    var userData;
DashboardService.fnGetUser(userId).then(function(oResponse) {
                        userData = oResponse.data;
                    })
return userData;
                }
            }

在ViewProfile状态的控制器中,我正在传递配置文件服务

angular.module('talentGraphApp')
.controller('ProfileViewCtrl', function($scope, $state, DashboardService, profile) {
    debugger;
    $scope.profile = profile;
    console.log(profile);
});

但是我无法在控制台中获取配置文件。

我不明白我哪里错了

resolve中,您返回userData之前,它已在promise回调中分配,因此当您将其传递给控制器

时,它是未定义的。

返回承诺代替

改变

 resolve: {
      profile: function(DashboardService, $stateParams) {                      
             var userId = $stateParams.id;            
             return DashboardService.fnGetUser(userId).then(function(oResponse) {
                        // return as resolved value
                        return oResponse.data;    
             });    
        }
}

路由配置中也没有$scope