-
Notifications
You must be signed in to change notification settings - Fork 3k
Resolve data in child state, but its query depends on a resolved object in the parent state. #151
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Sounds like #73? |
Hi Karsten! You're right! A fix for #73 would also resolve my problem. I'm currently struggling with a workaround for my problem. I'm sure you can help me on this one: The problem I have is that i somehow need to return a promise (as the state should not be displayed until everything is loaded). But I don't know how...
Then in my Controller i could access the data like this:
|
Do you want to wait until both main and dep are fully loaded, or just main? |
I want to wait for both (parentData and dependentData) to be fully loaded. |
Pretty sure this is the code... controller: 'myCtrl',
resolve: {
applicationData: ['$stateParams', '$http', '$q', function ($stateParams, $http, $q) {
var def = $q.defer();
var applicationData = {};
$http({method: 'GET', url: 'rest/parent/' + $stateParams.parentId}).
then(function (response) {
console.log("Parent data loaded");
applicationData["parentData"] = response.data;
// Load dependent data with an attribute of parent
$http({method: 'GET', url: 'rest/dependentData/' + response.data.parentId}).
then(function (response) {
console.log("Dependent data loaded");
applicationData["dependentData"] = response.data;
def.resolve(applicationData);
}
)
}
);
// Return the parentData promise
return def.promise;
}
]
}
.controller('myCtrl', ['$scope', 'applicationData', function ($scope, applicationData) {
console.log(applicationData["parentData"]);
console.log(applicationData["dependentData"]);
} |
Works like a charm! Thanks Tim! |
Cool! |
Dear all!
I'm having some issues with loading data in a child state. The problem is, that i need to resolve data in my child state which depends on an attribute of an object which was resolved in its parent state. So the hard coded objecttype parameter "APP" below is actually an attribute of an object which was loaded into scope by the parent state. Unfortunately I can't access the object in the parent scope using the following code: $scope.objectType....
How could I solve this problem? I must have missed something because I think it is a common problem to query detail data which depends on master data. Right??
Cheers and thank you in advance!
Michael
The text was updated successfully, but these errors were encountered: