简体   繁体   English

Angular2意外的结束标签“ li”

[英]Angular2 Unexpected closing tag “li”

I'm new to angular 2, I am using node npm to run angular.Without looping its working quiet good. 我是angular 2的新手,我正在使用节点npm来运行angular。而无需循环运行即可。 I am getting 'Unexpected closing tag "li" ("' in browser while compiling. have tried this but not working 我得到“意外的结束标记‘礼’(“”在浏览器在编译时, 都试过,但不工作

import {Component} from 'angular2/core';

    @Component({
        selector: 'test',
        template: `<ul>
<li *ngFor="let carPart of carparts">
    <h2>{{carPart.name}}</h2>
        <h2>{{carPart.description}}</h2>
        <h2>{{carPart.inStock}} in Stock</h2>
            </li>
    </ul>`
    })
    export class AppComponent {
        carparts = [
        {
            "id": 1,
            "name": "Super Tires",
            "description": "These tires are the very best",
            "inStock": 5
        },
        {
            "id": 2,
            "name": "Reinforced Shocks",
            "description": "Shocks made from kryptonite",
            "inStock": 4
        }];
    }

Thanks in advance

Your problem is here 你的问题在这里

<h2>{{carPart.name}}<h2>

It should be: 它应该是:

<h2>{{carPart.name}}</h2>

Also you use wrong variable name 你也使用错误的变量名

<li *ngFor="let carPart of carParts">

In your class is using carparts . 在您的课堂上使用carparts

And because you're using angular beta version it should be 并且由于您使用的是Beta版本,

<li *ngFor="#carPart of carparts">

You can use let only since beta17. 自beta17起,您只能使用let See also more information here: 另请参阅更多信息:

Inside of structural directives that declare local variables, such as *ngFor, usage of #... is deprecated. 在声明局部变量的结构指令(例如* ngFor)中,不建议使用#...。 Use let instead. 使用let代替。 now becomes 现在变成

I think your error lies here : 我认为您的错误就在这里:

<h2>{{carPart.name}}<h2>

You accidentally opened to h2 - instead of closing it. 您不小心打开了h2而不是将其关闭。 You're missing a / in your end-tag. 您在结束标记中缺少/ You are actually inside two h2 elements that you need to close before closing your li . 实际上,您在关闭li之前需要先关闭两个h2元素。

You are using an deprecated version of angular2, please update to RC4. 您使用的angular2版本已过时,请更新为RC4。 Since angular precompiles html, if you have any closing tags missed also will result in error 由于angular会预先编译html,因此如果缺少任何结束标记,也会导致错误

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM