AngularJS : What should my services return to controllers? -
i'm learning angular , i'm wondering if singletons (services & factories) should return promise object (containing required data) controller or if promises should resolved in factory first , pass response.data controllers? i've seen both methods used , wondering what's best practice. thanks.
there no best practice. depends heavily on situation @ hand - different situations/requirements call different approaches.
as rule of thumb, async data idea return promise.
yet, if data array bound view (e.g. ngrepeat
), idea return empty array later gets filled data arrive.
has benefit no logic required in controller.
(btw, $resource
uses approach 'get' methods.)
Comments
Post a Comment