简体   繁体   English

Angular 5花括号问题

[英]Angular 5 curly braces issue

After upgrading my app from angular v2 to v5, I faced some strange behavior with templates curly braces. 将我的应用程序从angular v2升级到v5后,模板花括号使我面临一些奇怪的行为。 If template element uses curly braces - nothing would be displayed without any console errors. 如果模板元素使用花括号-没有任何控制台错误,将不会显示任何内容。 For example: 例如:

<span>{{ 1 + 1 }}</span>
<span>{{ 'Test' }} test</span>
<span>Test</span>

would be rendered to 将呈现给

<span></span>
<span></span>
<span>Test</span>

There are no errors in console and existing component functions binded on (click) works perfectly normal. 控制台中没有错误,绑定(单击)的现有组件功能完全正常。 I really would be grateful for some hint or direction - what can cause such behavior 我真的很感谢一些提示或指导-什么会导致这种行为

some thoughts: I guess it's somehow related to router-outlet, cause outside of component, template renders as expected 一些想法:我想这与路由器出口有关,是组件外部的原因,模板呈现了预期的效果


Update: I don't know what exactly the problem was, but the it is definitely related to angular Router. 更新:我不知道到底是什么问题,但是这肯定与有角度的路由器有关。 I came out with 2 possible solutions: 1) Downgrading angular to v 4.1 2) Wrapping this.router.navigate method into this._ngZone.run(() => { }) So when using 我提出了两种可能的解决方案:1)将angular降级到v 4.1 2)将this.router.navigate方法包装到this._ngZone.run(()=> {})中

this._ngZone.run(() => { this.router.navigate(['/app']) });

template renders as expected. 模板将按预期方式呈现。 Still would be great to know what was wrong with the original code. 知道原始代码有什么问题还是很高兴。

我尝试这段代码并获得完美的输出。

2 Test test Test

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

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