【问题标题】:*ngFor causing template error*ngFor 导致模板错误
【发布时间】:2016-10-01 18:02:21
【问题描述】:

我收到此错误:

Template parse errors:↵Parser Error: Conditional expression result?categories requires all 3 expressions at the end of the expression [ngFor let category of result?categories] in ResultAttributesComponent@32:17

来自这个模板:

   <div class="row">
      <div class="col-sm-12">
         <div id="categories">
            <div *ngFor="let category of result?categories">
               <div class="category1">

               </div>
            </div>
         </div>
      </div>
   </div>

我做错了什么?

这是结果对象:

{
        id: 15,
        name: 'sugar free dark chocolate salted caramel',
        brand: "alpro",
        description: "Delicious sugar free dark chocolate in everyones favourite flavour, salted caramel.",
        image: "result-images/sugar_free_dark_chocolate_salted_caramel.png",
        rating: 9.2,
        nearbyShops:[],
        categories: ["dessert", "Baking"],
        averagePrice: 4.32,
        amount: "400g",
        reviews: [{
            id: 11,
            description: 'It was pretty amazing!',
            rating: 9.1,
            user: {
                id: 1,
                userName: "BeniaminoBaggins",
            },
            comments: [{
                id: 1,
                description: "great review!",
                user: {
                    id: 2,
                    userName: "IrishNimue"
                }
            }]
        }]
    }

【问题讨论】:

    标签: html angular ngfor


    【解决方案1】:

    您的循环表达式中缺少.

    <div *ngFor="let category of result?.categories">
    

    【讨论】:

      猜你喜欢
      • 2018-01-11
      • 2017-05-12
      • 2016-12-18
      • 2023-03-11
      • 2017-02-19
      • 2021-11-21
      • 2013-11-03
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多