我正在使用其中一个模型创建带有图像的MEAN应用。当页面加载时,图像在页面上呈现良好,但是在我的控制台中,我收到有关它们的错误:GET http://localhost:3000/%7B%7Bitem.photo_url%7D%7D 404 (Not Found),并且在运行npm和mongod的终端中:GET /%7B%7Bitem.photo_url%7D%7D 404 1.999 ms - 2083

我不确定是什么原因导致此错误,因为在前端似乎还可以。任何意见,将不胜感激!谢谢!

 .controller("IndexController", [ "$scope", 'items',
 function($scope, items)
   { $scope.items = items.items
     $scope.addItem = function(){
    items.create({
      title: $scope.title,
      photo_url: $scope.photo_url,
      maker: $scope.maker,
      description: $scope.description,
      price: $scope.price })
    $scope.title = '';
    $scope.photo_url = '';
    $scope.maker = '';
    $scope.description = '';
    $scope.price = '';
    $scope.upvotes = '';
   }
}];


 <h2>Style Review</h2>
 <div ng-repeat="item in items | orderBy: '-upvotes'">
    <span class="glyphicon glyphicon-heart-empty" ng-
    click="increaseUpvotes(item)"> </span>
    {{item.upvotes}}

    <p>{{item.title}}</p>
    <a href="#/items/{{item._id}}"><img class="indexImage" src="
        {{item.photo_url}}" alt="item image"/></a>
</div>

最佳答案

在您的HTML中-尝试使用

ng-src
ng-href


例如:

 <h2>Style Review</h2>
 <div ng-repeat="item in items | orderBy: '-upvotes'">
    <span class="glyphicon glyphicon-heart-empty" ng-
      click="increaseUpvotes(item)"> </span>
    {{item.upvotes}}

    <p>{{item.title}}</p>
    <a
        ng-href="#/items/{{item._id}}"> <--- SEE HERE (ng-href)
    <img class="indexImage"
     ng-src="{{item.photo_url}}"  <----- SEE HERE (ng-src)
     alt="item image"/></a>
    </div>


请参阅角度文档Angular 1 ng-src Doc

09-19 13:33