0

わかりましたので、ファクトリ/サービスを使用してコントローラー間でデータを共有することについてはたくさんありますが、私の問題に当てはまるものが見つかりません。答えを間違って解釈しているか、これは私が尋ねようとしている有効な質問です! うまくいけば後者です。

新しい http 呼び出しが行われ、ファクトリ イメージ オブジェクトが更新されたことをコントローラ 2 に認識させたいと思います。現時点では、一度解決され、その後の更新は無視されます。私は何を見落としていますか?

私の見解:

<div>
    <ul class="dynamic-grid" angular-grid="pics" grid-width="150" gutter-size="0" angular-grid-id="gallery" refresh-on-img-load="false" >
        <li data-ng-repeat="pic in pics" class="grid" data-ng-clock>
            <img src="{{pic.image.low_res.url}}" class="grid-img" data-actual-width = "{{pic.image.low_res.width}}"  data-actual-height="{{pic.image.low_res.height}}" />
        </li>
    </ul>
</div>

工場:

.factory('imageService',['$q','$http',function($q,$http){

  var images = {}
  var imageServices = {};
  imageServices.homeImages = function(){
    console.log('fire home images')
      images = $http({
        method: 'GET', 
        url: '/api/insta/geo',
        params: homeLoc
      })
  };
  imageServices.locImages = function(placename){
    console.log('fire locImages')
      images = $http({
        method: 'GET', 
        url: '/api/geo/loc',
        params: placename
      })
  };
  imageServices.getImages = function(){
    console.log('fire get images', images)
    return images;  
  }
  return imageServices;
}]);

コントローラー1:

angular.module('trailApp.intro', [])

.controller('introCtrl', function($scope, $location, $state, showTrails, imageService) {
  // run the images service so the background can load
  imageService.homeImages();

  var intro = this;

  intro.showlist = false;
  intro.data = [];

  //to get all the trails based on user's selected city and state (collected in the location object that's passed in)
  intro.getList = function(location) {

      intro.city = capitalize(location.city);
      intro.state = capitalize(location.state);
      //get placename for bg

      var placename = {placename: intro.city + ',' + intro.state};
      imageService.locImages(placename);
... do other stuff...

コントローラー2:

angular.module('trailApp.bkgd', [])
.controller('bkgdCtrl', ['$scope','imageService', 'angularGridInstance', function ($scope,imageService, angularGridInstance) {
  $scope.pics = {};
    imageService.getImages().then(function(data){
      $scope.pics = data;
      console.log($scope.pics);
    });
}]);
4

1 に答える 1