【问题标题】:Error: GET 404 (Not found) error for images, but the images are showing up fine错误:图像的 GET 404(未找到)错误,但图像显示正常
【发布时间】:2017-08-27 18:16:35
【问题描述】:

我正在创建一个 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>

【问题讨论】:

  • 请分享您的代码。
  • 我将代码粘贴在下一个评论部分。我是 SO 的新手,并试图在其中标记你,但我不确定它是否有效
  • %7B = "|"和 %7D = "{"。因此,如果您要重写链接,它将是 localhost:3000/||item.photo_url}} 这意味着您的 Angular 没有绑​​定到 html。一些将“或”条件作为 photo_url 字符串的一部分应用的地方。分享你的 Angular 控制器和相应的 html 模板
  • 控制器:` .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 = ''; } `
  • html: `

    风格回顾

    {{item.upvotes}}

    {{item.title}}

    `

标签: angularjs node.js http-status-code-404 mean-stack


【解决方案1】:

在您的 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

【讨论】:

    【解决方案2】:

    我认为%7B%7Bitem.photo_url%7D%7D 这是一个错误的地址。 请签入console.log()图片网址 %7B%7 - 这不是关于文件名的意思 Bitem.photo_url 这是我认为的 var 请为这个问题粘贴一些代码

    【讨论】:

    • 在我的 index.html 文件中调用图像的行:
    • 在我的模式文件中:in my models folder for my ItemSchema: var ItemSchema = new mongoose.Schema({ title: String, photo_url: String, maker: String, description: String, price: Number, upvotes: {type: Number, default: 0}, reviews: [{type: mongoose.Schema.Types.ObjectId, ref: "Review"}] })
    • 和照片网址:photo_url: "https://cdn.shopify.com/s/files/1/0233/5133/products/Polished-Rose-Gold_Blush-Leather_1_335x335.jpg?v=1441941608"@Bitmask
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-02-28
    • 2021-03-15
    • 1970-01-01
    • 2022-01-18
    • 2019-11-10
    • 2017-01-17
    相关资源
    最近更新 更多