【发布时间】:2018-02-01 10:09:18
【问题描述】:
所以我想使用 Angular 开发一个吃豆人游戏,我想为此使用 SVG,我想创建一个嵌入 pacman.component 的 board.component。
board.component 将有一个 <svg></svg> 和 pacman.component 将有一个 <circle></circle> 但 Angular 在我的 pacman.component 中抛出此错误:
[Angular] 'circle' 不是已知元素:
- 如果“circle”是一个 Angular 组件,则验证它是该模块的一部分。
- 要允许任何元素将“NO_ERRORS_SCHEMA”添加到此组件的“@NgModule.schemas”。
修复这些错误后,我最终得到了这个 SVG:
<svg _ngcontent-c0="" width="100" height="100">
<app-pacman _ngcontent-c0="" _nghost-c1="">
<circle _ngcontent-c1="" fill="yellow" r="25" cx="10" cy="10"></circle>
</app-pacman>
</svg>
现在唯一的问题是 angular 用 <app-pacman></app-pacman> 包裹了 pacman.component,这使得 circle 不起作用。
只是想知道 Angular 的做法是什么?我不想将整个 svg 代码 (svg, circles, paths, etc...) 放在一个组件中。
谢谢。
编辑:
board.component.html:
<svg [attr.width]="width" [attr.height]="height">
<app-pacman></app-pacman>
</svg>
pacman.component.html:
<circle [attr.cx]="cx" [attr.cy]="cy" r="25" fill="yellow"></circle>
【问题讨论】:
-
贴出你的组件类代码
-
请发布两个组件模板