簡體   English   中英

$ state.go似乎不起作用

[英]$state.go doesn't seems to be working

我有一種情況,當單擊搜索到的項目時,我需要加載其他狀態

這是我的HTML代碼

<span class="item-title" ng-click="fnViewProfile()">
      <span> {{item.name}} </span>
</span>

以下是我的控制器代碼:

$scope.fnViewProfile = function() {
        $state.go("ViewProfile", {
            "id": 10215
        });
    }

在我的app.js中,我有一個resolve函數,在該函數中我執行了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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM