Here is my code:
.state("dashboard.userRoles", { url: "/user/:id/roles", controller: "userRolesController as vm", templateUrl: "app/auth/users/user-roles.html", resolve: { user: function (userResource, $stateParams) { return userResource.get({ id: $stateParams.id }).then(function (res) { return res.data; }); }, roles: function($http, $stateParams) { var url = appSettings.authApiBaseUrl + "api/accounts/users/" + $stateParams.id + "/roles"; return $http.get(url).then(function(res) { return res.data; }); }, loadMyFiles: function($ocLazyLoad) { return $ocLazyLoad.load({ name: "app", files: [ "app/auth/users/userRolesController.js" ] }); } } })
If I go to dashboard.userRole and look in fiddler, I see a request for a user resource, but not for the role. If I comment on the user: section, I see a request for roles in the violin. Why can't I solve both issues? Should I just send the identifier to the controller and is that all there?
I tried to avoid collecting data in the controller, as it should just be stitching between the view model file and ui. Maybe it doesn't matter? Thanks in advance.
Edit 1: Okay, I can change the code to this and see both requests shown in the script, and both of them return correctly formatted json data:
.state("dashboard.userRoles", { url: "/user/:id/roles", controller: "userRolesController as vm", templateUrl: "app/auth/users/user-roles.html", resolve: { user: function (userResource, $stateParams) { return userResource.get({ id: $stateParams.id }).$promise; }, roles: function($http, $stateParams) { var url = appSettings.authApiBaseUrl + "api/accounts/users/" + $stateParams.id + "/roles"; return $http.get(url).then(function(res) { return res.data; }).$promise; }, loadMyFiles: function($ocLazyLoad) { return $ocLazyLoad.load({ name: "app", files: [ "app/auth/users/userRolesController.js" ] }); } } })
However, the roles entered into the controller are always "undefined". The user is filled in correctly. And the answer from the violinist shows the roles that are being returned, so I'm not sure why they are undefined. Here is the controller code.
"use strict"; angular .module("app") .controller("userRolesController", [ "user", "roles", function (user, roles) { console.log("app.userRolesController.function()"); var vm = this; vm.user = user; vm.roles = roles; } ]);