promise.then连续多次调用控制器后取消,只返回数据

时间:2015-09-02 09:59:41

标签: javascript angularjs angularjs-directive

我的问题是,我想要三个独立的控制器实例,我从html调用它。

我的控制器是这样的

app.controller("overallCtrlDemo", function($scope,$rootScope,overAllService,lookupService,uiGmapGoogleMapApi)    {

    var promise=overAllService.getOverAll();
    promise.then(function(data){
        $scope.timeSeries1 = $rootScope.helpers.d3FormatJsonDualAxis(data.data);
        $scope.generic = $scope.timeSeries1;
        $scope.sunBurst = $rootScope.helpers.d3FormatSunburst(data.data);
    })

})

我在html中有三个指令说

  1. timeseries1(使用timeseries1数据)
  2. generic(使用通用数据)
  3. sunBurst(使用sunBurst数据)
  4. 但是当html呈现它会调用控制器三次但是 promise.then函数仅返回上次调用的状态1。她是下面的图片

    <div id="topProduct-graph" class="chart no-padding"  ng-controller="overallCtrlDemo">
        <topproducts id = "topProducts" data-role="concentric" data-width=400 data-height=400  data-thickness=13 val=topProducts style="position:absolute;"></topproducts>
    </div>
    
    <div class="trendMap" style="width:1213px;" ng-controller="overallCtrlDemo">
        <generictimeseries id="genericTimeseries" val="generic" saleorquantity="saleOrQuantity"></generictimeseries>
    </div>
    

    enter image description here

0 个答案:

没有答案