错误:意外字符“ EOF”(模板中是否有未转义的“ {”?使用“ {{'{'}}””)进行转义。)(在Angular2 +中

时间:2018-08-13 12:06:56

标签: angular

我正在尝试在angular4的.html(模板)中实现以下代码(以下代码) 在这里,如何处理多个括号和大括号并解决此错误?

But getting error as:-
ERROR Error: Uncaught (in promise): Error: Template parse errors:
Unexpected character "EOF" (Do you have an unescaped "{" in your template? Use "{{ '{' }}") to escape it.) ("

app.component.html

<div>
    <code>
        <pre>
            @Component({
                selector: 'app-projection',
                templateUrl: './projection.component.html',
                styleUrls: ['./projection.component.css']
            })
        </pre>
    </code>
</div>

2 个答案:

答案 0 :(得分:2)

错误消息清楚地表明,

  

意外的字符“ EOF”(您的字符中是否有未转义的“ {”   模板?使用“ {{'{'}}”)对其进行转义。)(“

确保要在 {字符之前添加'(引号),您应将代码修改为

<div>
    <code>
        <pre>
            @Component({{ '{' }}
                selector: 'app-projection',
                templateUrl: './projection.component.html',
                styleUrls: ['./projection.component.css']
            })
        </pre>
    </code>
<div>

希望这会有所帮助!

答案 1 :(得分:0)

编辑

为什么要在HTML中声明一个“内联”组件?

您应该在一个单独的文件中声明一个组件,然后使用选择器在HTML中使用它

例如

<pre>
  <app-your-component-selector></app-your-component-selector>
</pre>

原始

该错误表明您的HTML中还有一个 {,也许是这样的

<div> { --This will cause the error </div>
<div> { {{'This too'}} </div>
<span id="{{maybeHere}"> </span>