Javascript angular 2模板分析错误意外字符EOF
我刚刚在visual studio中打开并重新运行我的angular 2 TS应用程序 上一次我这么做的时候,我确信它没有任何错误 现在,我在浏览器控制台中遇到此错误,应用程序未完全加载:Javascript angular 2模板分析错误意外字符EOF,javascript,angular,Javascript,Angular,我刚刚在visual studio中打开并重新运行我的angular 2 TS应用程序 上一次我这么做的时候,我确信它没有任何错误 现在,我在浏览器控制台中遇到此错误,应用程序未完全加载: EXCEPTION: Template parse errors: Unexpected character "EOF" (" test </foot[ERROR ->]"): AppComponent@22:6 angular2.js:23083 EXCEPTION: Template
EXCEPTION: Template parse errors:
Unexpected character "EOF" ("
test
</foot[ERROR ->]"): AppComponent@22:6
angular2.js:23083 EXCEPTION: Template parse errors:
Unexpected character "EOF" ("
test
</foot[ERROR ->]"): AppComponent@22:6BrowserDomAdapter.logError @ angular2.js:23083
angular2.js:23083 STACKTRACE:BrowserDomAdapter.logError @ angular2.js:23083
angular2.js:23083 Error: Template parse errors:
Unexpected character "EOF" ("
test
</foot[ERROR ->]"): AppComponent@22:6
at new BaseException (http://localhost:55555/lib/angular2.js:7351:21)
at TemplateNormalizer.normalizeLoadedTemplate (http://localhost:55555/lib/angular2.js:20019:15)
at http://localhost:55555/lib/angular2.js:20008:24
at Zone.run (http://localhost:55555/lib/angular2-polyfills.js:1243:24)
at Zone.run (http://localhost:55555/lib/angular2.js:13438:32)
at zoneBoundFn (http://localhost:55555/lib/angular2-polyfills.js:1220:26)
at lib$es6$promise$$internal$$tryCatch (http://localhost:55555/lib/angular2-polyfills.js:468:17)
at lib$es6$promise$$internal$$invokeCallback (http://localhost:55555/lib/angular2-polyfills.js:480:18)
at lib$es6$promise$$internal$$publish (http://localhost:55555/lib/angular2-polyfills.js:451:12)
at http://localhost:55555/lib/angular2-polyfills.js:123:10
-----async gap-----
Error
at _getStacktraceWithUncaughtError (http://localhost:55555/lib/angular2-polyfills.js:2236:29)
at Zone.fork (http://localhost:55555/lib/angular2-polyfills.js:2285:47)
at Zone.bind (http://localhost:55555/lib/angular2-polyfills.js:1218:53)
at bindArguments (http://localhost:55555/lib/angular2-polyfills.js:1401:36)
at lib$es6$promise$promise$$Promise.obj.(anonymous function) [as then] (http://localhost:55555/lib/angular2-polyfills.js:1413:46)
at TemplateNormalizer.normalizeTemplate (http://localhost:55555/lib/angular2.js:20007:44)
at TemplateCompiler.normalizeDirectiveMetadata (http://localhost:55555/lib/angular2.js:24233:39)
at http://localhost:55555/lib/angular2.js:24306:24
at Array.map (native)
at Array.map (http://localhost:55555/lib/es6-shim.js:1113:14)
-----async gap-----
Error
at _getStacktraceWithUncaughtError (http://localhost:55555/lib/angular2-polyfills.js:2236:29)
at Zone.fork (http://localhost:55555/lib/angular2-polyfills.js:2285:47)
at NgZone._createInnerZone (http://localhost:55555/lib/angular2.js:13426:39)
at new NgZone (http://localhost:55555/lib/angular2.js:13292:32)
at createNgZone (http://localhost:55555/lib/angular2.js:12475:12)
at PlatformRef_.application (http://localhost:55555/lib/angular2.js:12550:31)
at Object.bootstrap (http://localhost:55555/lib/angular2.js:24805:64)
at execute (http://localhost:55555/app/main.js:28:23)
at u (http://localhost:55555/lib/system.js:5:3330)
at Object.execute (http://localhost:55555/lib/system.js:5:6218)BrowserDomAdapter.logError @ angular2.js:23083
:55555/app/main.js:31 BaseExceptionmessage: "Template parse errors:↵Unexpected character "EOF" ("↵ test
↵
↵</foot[ERROR ->]"): AppComponent@22:6"stack: "Error: Template parse errors:↵Unexpected character "EOF" ("↵ test
↵
↵</foot[ERROR ->]"): AppComponent@22:6↵ at new BaseException (http://localhost:55555/lib/angular2.js:7351:21)↵ at TemplateNormalizer.normalizeLoadedTemplate (http://localhost:55555/lib/angular2.js:20019:15)↵ at http://localhost:55555/lib/angular2.js:20008:24↵ at Zone.run (http://localhost:55555/lib/angular2-polyfills.js:1243:24)↵ at Zone.run (http://localhost:55555/lib/angular2.js:13438:32)↵ at zoneBoundFn (http://localhost:55555/lib/angular2-polyfills.js:1220:26)↵ at lib$es6$promise$$internal$$tryCatch (http://localhost:55555/lib/angular2-polyfills.js:468:17)↵ at lib$es6$promise$$internal$$invokeCallback (http://localhost:55555/lib/angular2-polyfills.js:480:18)↵ at lib$es6$promise$$internal$$publish (http://localhost:55555/lib/angular2-polyfills.js:451:12)↵ at http://localhost:55555/lib/angular2-polyfills.js:123:10"__proto__: __(anonymous function) @ :55555/app/main.js:31
或app.html
<header>
<nav>
<h1>Hello {{ name }}</h1>
<ul>
<li router-active>
<a [routerLink]="['Index']">Schoolyears</a>
</li>
<li router-active>
<a [routerLink]="['Administration']">Administration</a>
</li>
</ul>
</nav>
</header>
<main>
<router-outlet></router-outlet>
</main>
<footer>
test
</footer>
你好{{name}
-
我遇到了意外的字符“EOF”错误,很难调试,我是如何解决这个问题的:
我的组件的模板文件中有一条html注释:
我把它改成:
这不是第一次,每次我出现这个错误时,我都会修复html注释,以
开头,而不是-->
,问题就解决了
见:
在我的例子中是注释,但我认为一般来说,您需要有效的html,否则解析器可能会抛出该错误。此错误是由于a2和webpack html loader之间的某些不兼容造成的。在中使用的变通方法是
更多关于这方面的信息可以在中找到,我注意到当Angular2应用程序中的HTML无效时,您会得到它。因此,尝试通过消除、不寻常的html标记等方式进行调试。。在我的例子中,我错过了结束。这个错误是很棘手的,因为错误信息经常会误导人。错误将显示最后一行HTML;但是,不要在那里搜索问题!这种情况很简单,因为事先没有正确关闭标记
通过关闭缺少关闭标记的标记来修复此错误。有时,就像我在
的例子中一样,这很难捕捉到,因为如果
未关闭,Angular就满足了;但是,
必须关闭。
如果您想知道哪些HTML元素标记必须关闭,只需搜索您感兴趣的特定元素的标记省略
考虑通过一个过梁运行HTML,以便快速捕获这些错误强>
我的情况的代码示例
在我的例子中,我没有关闭我的
元素之一
以前我的代码如下
<div class="form-group col-sm-6">
<label for="example" class="form-label">Example</label>
<textarea class="form-control" name="example" formControlName="example" lines="2">
</div>
<div class="form-group col-sm-6">
<label for="example" class="form-label">Example</label>
<textarea class="form-control" name="example" formControlName="example" lines="2"></textarea>
</div>
例子
为了解决这个问题,我只需关闭
元素,如下所示
<div class="form-group col-sm-6">
<label for="example" class="form-label">Example</label>
<textarea class="form-control" name="example" formControlName="example" lines="2">
</div>
<div class="form-group col-sm-6">
<label for="example" class="form-label">Example</label>
<textarea class="form-control" name="example" formControlName="example" lines="2"></textarea>
</div>
例子
您是否收到任何404错误?您的其他组件是什么样的(学年
,管理
,路由活动
)?无404个错误。RouterActive来自。在学年/管理中没有编译错误。我完全删除了页脚,保存并刷新,然后它再次工作!当我将任何html标记放在主标记之后时,我再次遇到同样的错误,那是什么?这太奇怪了,当我在主标记后没有任何html标记的情况下重新启动服务器时,我发现主标记有错误,请检查您的导入顺序-我在几周前遇到了相同的意外字符“EOF”
,结果是由相同的事情引起的。。。真的很难调试;我在app.component.ts中有7个导入。这是128个不同的订单;-)就像你说的那样,它只工作了一次又一次不…谢谢你,伙计,我为这个错误浪费了我的一天
<div class="form-group col-sm-6">
<label for="example" class="form-label">Example</label>
<textarea class="form-control" name="example" formControlName="example" lines="2"></textarea>
</div>