Share async data between controllers without making multiple requests

后端 未结 4 1223
盖世英雄少女心
盖世英雄少女心 2021-02-14 20:21

I\'m trying to make a single $http request to get one of my JSON files and use the data across all my controllers.

I saw on egghead.io how to share data acr

4条回答
  •  既然无缘
    2021-02-14 20:31

    Since you are using a promise, to access the data returned by promise use the callback syntax

    function appInstallerDetailCtrl($scope, $routeParams, Data) {
      $scope.appId = $routeParams.appId;
       Data.then(function(returnedData) {
            $scope.apps=returnedData;
            console.log($scope.apps);
            for (var i in $scope.apps)
               console.log(i)   
       });   
    }
    

    Make sure this

    defer.resolve(result.data.versions.version);
    

    resolve returns array, for the above code to work. Or else see what is there in data and ajust the controller code.

提交回复
热议问题