热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

Angular没有显示响应数据-Angulardidn'tshowresponsedata

Hereisbackendfunction这是后端功能userDetail:function(req,res){User.findOne().where

Here is backend 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);
              }
            });
        }
      });
  }

Here is frontend resource 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');
            }
        }

    }
})();

resource function call on controller

资源函数调用控制器

 vm.userDetail= userAccountsResource.getUserDetail();

backend send response data is

后端发送响应数据是

{ 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' } ] }
but {{vm.userDetail}} did n't show any thing

it shown {{}}

它显示{{}}

why is that..? function is properly link to the back end function and it return correct response but why is that it shown {{}} like that

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

1 个解决方案

#1


2  

When making a asynchronous call, if the request is not wrapped in $http you must notify angular that the model has changed so the view can sync.

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

Try to add $scope.$apply() when you recieve the response from the server

当您收到服务器的响应时,尝试添加$ scope。$ apply()


推荐阅读
author-avatar
舞倾城2010_217
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有