angular - 角度自定义模板插值用花括号中断
问题描述
我是 Angular 的新手,我找不到并回答我的问题。
我想更改 Angular 插值以使其与 Smarty 模板兼容,因此我将默认 ['{{','}}'] 更改为 ['[[',']]'] 或 ['[ ', ' ]'] 但如果模板包含以 { 开头的内容,我必须使用新的插值对其进行转义。
我创建了一个新应用
ng new new-app
然后我将 app.component.ts 装饰器编辑为:
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css'],
interpolation: ['[[',']]']
})
export class AppComponent {
title = 'Hello World!';
}
然后我在 app.component.html 上添加了带有新插值的新变量
<h1>[*title*][[title]]{{title}}</h1>
我期望
<h1>[*title*]Hello World!{{title}}</h1>
但我收到一个 Angular 错误
Unexpected character "EOF" (Do you have an unescaped "{" in your template? Use "{{ '{' }}") to escape it.) ("<h1>[*title*]Hello World!{{title}}</h1>
要解决这个问题,我需要更新模板
<h1>[*title*]Hello World![["{{"]]title}}</h1>
如果新插值是“[[”“]]”,为什么我必须转义“{{”?
解决方案
推荐阅读
- excel - 试图了解在 Range 对象上使用 Item 属性和 Cells 属性之间的区别
- javascript - 如何改变
标签文本,不删除下划线或斜体格式?
- r - 在某些观察之前选择组,通过 R 中的分组 var 分隔
- java - 如何为 Payara EJB__TIMER__TBL 指定模式
- shell - 按下 ctrl-c 与多个进程将它们的标准输出管道到单个进程中会杀死 shell
- oop - 如何通过反射 API 在 Java 中获取已处理的对象并为其设置新值?
- sql - Oracle Query 跟踪具有特定日期上下文的表的更改
- pandas - 如何确定为什么熊猫数据框缺少最后几行
- ssh - 忽略 SSH 超时以继续 Gitlab CI
- blockchain - 在 IBM Blockchain 中启动我的业务网络时出错