Reputation: 451
I'm using angular. I have a resource object called $scope.recruitmentProject and this object has $save() method.
I need to pass this object to another page so I did it like this-
$state.go('company.editRecruitmentProject', {'project': angular.toJson(recruitmentProject)});
on the other page I get this object like this-
$scope.project = angular.fromJson( decodeURIComponent( $stateParams.project ) );
now $scope.project don't have the $save() method.
What should I do to make it work?
Upvotes: 0
Views: 24
Reputation: 1343
Because JSON can only serialize data, not functions. So in this case, I would suggest you to put the project
object into a separated service, so both controller can access it.
// In ProjectService.js
.service('ProjectService', function() {
// Put project related logic here
}
Then inject ProjectService
into your controller and use it.
Upvotes: 1