4

私のコントローラーでは、サービスを呼び出します。このサービスは、画像への URL を提供する PHP ファイルにリクエストを送信します。

この理由は、画像が「Media Vault」内に存在するためです。つまり、表示するには、次のようにハッシュされた URL を生成する必要があります。

http://xxxx.vo.llnwd.net/o35/s/xxx/test/thumbs/slide1.jpg?e=1365006137&h=5852aeaf5beeeebff05a601801b61568

上記の URL は既に有効期限が切れているため、その特定のリンクからは何も表示されません。

私のイメージタグは次のようになります:

<img id="thumbnail" class="glow" ng-src="{{currentThumb}}" width="200" height="150"/>

私のコントローラーの currentThumb は次のとおりです。

$scope.currentThumb = ImageService.getImage({
    'type' : 'thumb',
    'index' : $scope.currentIndex + 1,
    'location' : $scope.location
});

私のサービスは次のようになります。

app.factory('ImageService', function($http)
{
    var image = null;
    return {
        promise:null,
        getImage: function($data)
        {
            this.promise = $http.post('resources/auth.php',$data, {timeout:20000}).success(function(response)
            {
                image = response;
                log(response);
            })
        }
    }
});

現在の ImageService は正常に URL を返し (少なくともコンソールに URL が表示されます)、コンソールでログ結果をクリックすると、画像が正常に読み込まれます。画像が更新されない理由はありますか?

4

1 に答える 1

2

これをどのように呼び出す必要があるのか​​ わかりませんが、別の方法ImageService.getImage()として、コントローラーの解決ブロックで呼び出すことをお勧めします。そうすれば、コントローラーとビューが処理される前にすべてがロードされます。

jsfiddle

http://jsfiddle.net/HYDmj/1/

見る

<div ng-app="main">
  <div ng-controller="ExampleController">
    <h1>currentThumb</h1>
      <img ng-src="{{currentThumb.data}}">
  </div>
</div>

コード

var app = angular.module('main',[]);

app.factory('ImageService', function($http)
{
    image = null;
    return {
        getImage: function($data)
        {
            image = $http.post('http://dopserv1.dop.com/test/auth.php', $data, {timeout:20000})
            return image
        }
    }
});

function ExampleController($scope, ImageService)
{
    $scope.currentThumb = ImageService.getImage({
        'type' : 'thumb',
        'index' : 1,
        'location' : 'http://digitalout.vo.llnwd.net/o35/s/mobilevforum/test/'
    });
}
于 2013-04-03T20:26:45.607 に答える