[英]$state.go doesn't seems to be working
I have a scenario where when click on searched item i need to load different state 我有一种情况,当单击搜索到的项目时,我需要加载其他状态
Here is my html code 这是我的HTML代码
<span class="item-title" ng-click="fnViewProfile()">
<span> {{item.name}} </span>
</span>
below is my controller code: 以下是我的控制器代码:
$scope.fnViewProfile = function() {
$state.go("ViewProfile", {
"id": 10215
});
}
In my app.js i have a resolve function where i did ajax call to get the data before the html gets loaded 在我的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;
}
}
In controller of ViewProfile state i am passing the profile service 在ViewProfile状态的控制器中,我正在传递配置文件服务
angular.module('talentGraphApp')
.controller('ProfileViewCtrl', function($scope, $state, DashboardService, profile) {
debugger;
$scope.profile = profile;
console.log(profile);
});
But i am unable to get profile in the console. 但是我无法在控制台中获取个人资料。
I dont understand where i am going wrong 我不明白我要去哪里错了
Any help would be appreciated. 任何帮助,将不胜感激。
In the resolve
you return userData
before it has been assigned inside the promise callback, so it is undefined when you pass it to controller 在
resolve
您在将userData
分配到promise回调之前将其返回,因此在将其传递给控制器时未定义
Return the promise instead 退还诺言
Change to 改成
resolve: {
profile: function(DashboardService, $stateParams) {
var userId = $stateParams.id;
return DashboardService.fnGetUser(userId).then(function(oResponse) {
// return as resolved value
return oResponse.data;
});
}
}
Also there is no $scope
in the routing config 路由配置中也没有
$scope
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.