parse.com数据到货前的离子离子视图负载

时间:2015-10-23 07:02:19

标签: angularjs parse-platform ionic-framework ionic

我是离子框架的新手。 我正在创建app,我使用Ionic框架和Parse.com作为后端..

问题: 我已经创建了从解析表中获取客户数据(name,address,cust_photo ..)的服务,并且这个服务在控制器函数中被调用,而不是我在ion-view的div标签中使用的这个函数(ng-init) =" customer_data()")但我的离子视图显示数据或某些时候我认为是因为在parse.com数据可用之前离子视图渲染..

在服务和控制器console.log(customerdata)中显示..

我读过Promise,看但不知道如何使用......

.service {
    function() {
        //parse.com query method to get data from parse
        return customerdata; 
    }
}


.controller {
    function(...) {
        $scop.customer_data() {
            ......
        }
    }
}

<ion-view>
<div ng-init="customer_data()">

//customer info....`


</div>
</ion-view>

我该如何解决这个问题?你能给我一些代码片段吗?

1 个答案:

答案 0 :(得分:1)

承诺,手表和回调是解决问题的三种可能方式。我将描述回调解决方案。

要确保在$ scope中包含检索到的值,只需将回调函数传递给服务方法:

.service {
    function() {
        //parse.com query method to get data from parse
        getCustomerData: function(callback){
          //get values
          callback(values);
        } 
    }
}


.controller {
    function(...) {
        $scope.customer_data() {
            myService.getCustomerData(function(values){
              $scope.customer_data = values;
            });
        }
    }
}
相关问题