I have a couple relatively large javascript objects that I use to help out with data bindings, layout of the page and a lot of logic in the controller. I have moved these objects in a service. For instance, here's an abbreviated example:
getEntityTypes: function() {
return [{
displayName: "User",
value: "users"
}, {
displayName: "Group",
value: "groups"
}, {
displayName: "Section",
value: "sections"
}];
}
Previously, I've had all these objects defined in the controller. My main question is, will the controller get these staticly defined objects in a synchronous fashion? Or do I need to give it a callback and treat it as if it's an asynchronous request (like if its making a http.get request) Or can I do something like this:
$scope.entityTypes = coolService.getEntityTypes();
And then I can immediately do stuff with $scope.entityTypes
?
I am currently relying on $scope.entityTypes
within the callback of a web request, so it's not causing me any problems, but I'm not sure if this is like a bad idea or not?
Any advice is helpful,
The controller will receive the objects in a synchronous manner. In its root, these are basically method calls between two objects.