Angular没有显示响应数据

这是后端function

userDetail : function(req,res){ User.findOne().where({id : req.userID}).exec( function findOneCB(err, result) { if (err) { sails.log.error("Error Occurred : "+ err); } if(result != undefined ){ Account.find().where({userID: req.userID},{StatusCode :"Successful"}).exec( function findCB(err, accounts) { if (err) { sails.log.error("Error Occurred : "+ err); } if(accounts != undefined ){ var sendData={ userData:result, accountData :accounts }; console.log(sendData); res.json(sendData); } }); } }); } 

这是前端资源function

 (function (){ "use strict"; angular.module('userAccounts').factory('userAccountsResource',[ "$resource","$http",userAccountsResource]); function userAccountsResource($resource,$http){ return { getApprovedAccounts:function(){ return $resource('api/account/approvedBankAccounts'); }, getUserDetail : function(){ return $http.get('api/user/userDetail'); } } } })(); 

控制器上的资源function调用

  vm.userDetail= userAccountsResource.getUserDetail(); 

后端发送响应数据是

 { userData: { email: 'thusitha@gmail.com', userName: 'thusithz', userRole: 'Standard', selectedAccountList: [ { accountName: 'HSBC name', CFIXID: 'HSBC_CFIXID', id: '563c4d7e802127d51b3d80c7', StatusCode: 'Pending' }, { accountName: 'NSB plus', CFIXID: 'NSB_CFIXID', id: '563c4de1802127d51b3d80c8', StatusCode: 'Pending' } ], createdAt: '2015-11-06T05:10:18.690Z', updatedAt: '2015-11-06T05:52:24.820Z', verifyCode: '1446786618698FfL2_gHGexhOb_JQ', pincode: '1111', id: '563c363aa45b2d841afc63ab' }, accountData: [ { TimeStamp: '1446797352', TransactionID: 'LGPS201511613253518097', SecretTransactionKey: 'HSBC_CFIXID03636867', ReplyID: '35753', StatusCode: 'Successful', StatusDescription: 'Authentication Failed', Tags: '', ReturnURL: '', userID: '563c363aa45b2d841afc63ab', accountName: 'HSBC plus', CFIXID: 'HSBC_CFIXID', VerificationCode: 'LGPS3309914431991402', createdAt: '2015-11-06T07:55:35.229Z', updatedAt: '2015-11-06T07:55:35.229Z', id: '563c5cf7463ef3eb0aeaf57a' } ] } 

但是{{vm.userDetail}}没有显示任何内容

它显示{{}}

这是为什么..? 函数正确链接到后端函数,并返回正确的响应,但为什么它显示{{}}

在进行asynchronous调用时,如果请求未包含在$ http中,则必须通知angular色模型已更改,以便视图可以同步。

尝试添加$scope.$apply()当你从服务器收到响应