Referring to the snippet below, how do I get the controller function (DashboardController) to 'wait' for the return from crmApi? I've debugged enough to know crmApi returns the results I like, but DashboardController exits before I set self.user.

I'm weak on promises, but perhaps I also need to find a better place to call crmApi? Is it a better practice to call crmApi within, e.g., angular.module('tournament').config(['$routeProvider' ...

angular.module('tournament').component('dashboard', { templateUrl: '~/tournament/dashboard/dashboard.template.html', controller: ['$routeParams', 'crmApi', function DashboardController($routeParams, crmApi) { var self = this;

  // e.g., dashboard/43
  if ($routeParams.userId !== undefined) self.userId = $routeParams.userId;

  self.user = crmApi('Contact', 'getsingle', {
    "sequential": 1,
    "return": ["display_name","modified_date"],
    "id": self.userId
        // Success
        function(result) { 
            return result; // How can I get self.user to 'wait' for this return?
        // Failure
        function (error) { 
            CRM.alert(ts('Could not get user record ID of %1, error = %2', {1: userId, 2: error}),ts('Not Found'),'error'); 

] });

1 Answer 1


I finally remembered that promises return callbacks. So, instead of

return result

in the then of the crmApi promise, using

self.user result

does exactly what I need.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.