Issue
I am in the process of migrating an AngularJS-Application to Angular, component by component with the help of ngHybrid. So far it works, but now I stumbled upon an weird AngularJS-Service with a function which gets passed an AngularJS-Component-Controller as function parameter:
// Service
getDocumentList(requestData, ctrl) {
// edits stuff on ctrl, like adding variables and modifying values
}
// calling component
var ctrl = this;
documentService.getDocumentList(requestData, ctrl);
I know I know, I for myself never would have created a service method which modifies a controller via passed reference, its horrible practice, but I am just migrating it and before refactoring it I'd rather make it work with as little effort as possible. I'm just not sure if it is possible with Angular to pass a reference, cause I don't have controllers anymore but classes... Is there a way to make it work it can I only refactor it so that the service returns something which the calling component works with (as it should be...)?
Solution
in Angular component class usually fulfills controller functions. so the same code - passing this should work. but there can be issues with change detection, especially if you are using onPush strategy
Answered By - Andrei
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.