0

I have a template like this:

<img class="picto" 
    ng-repeat="module in modules" 
    ng-src="{{module.Source}}" 
    title="{{module.Title}}" 
    ng-click="module.handler();"/>

When I set the $scope.modules array using static code, everything works fine, and the images are fetched via GET using media type "image/gif" (for gif files). However, when I retrieve the same array using $http.get() - see the code below -, angular tries to retrieve the images using media type "text/html" which results in an 404 error:

$http.get('/api/modules', {})
    .success(function (data) {
        $http.defaults.get = { 'Content-Type': 'image/gif' }; // apparently useless
        $scope.modules = data;
        for (var module in $scope.modules) {
            $scope.modules[module].handler = function () { alert(this.Id); };
        }
        delete $http.defaults.get; // ...useless 
    });

Trying to add a header default did not help either (// apparently useless). Can you see what's wrong?

4

1 回答 1

0

尝试使用Accept: 'image/gif'而不是Content-Type: 'image/gif'.

Content-Type头描述了您发送到服务器的数据格式。标Accept头描述了您从服务器响应中接受的数据格式。

于 2013-06-25T00:43:18.930 回答