考虑以下组件,它匹配
很明显,我可以在组件的模块上放置“NO_ERRORS_SCHEMA”,但我不愿意这样做,因为模块中还有其他组件,并且因为我希望未知元素错误检查能够起作用。
那么,我该如何告诉Angular它应该将这个特定组件的内容视为SVG内容?如果这不可能,是否还有其他干净的方法来解决这个问题?
<svg icon="close"></svg>
,用于显示图标:@Component({
selector: 'svg[icon]',
template: `<use [attr.xlink:href]="'icons.svg#'+icon"></use>`
})
export class SvgIconComponent {
@Input() icon: string;
}
这种情况下会失败,因为Angular无法找到<use>
元素,它不知道组件内容在<svg>
中。如果Angular能够注意到selector
确保了这个事实就好了,但它并没有。
具体的错误信息如下:
Uncaught Error: Template parse errors:
'use' is not a known element:
1. If 'use' is an Angular component, then verify that it is part of this module.
2. To allow any element add 'NO_ERRORS_SCHEMA' to the '@NgModule.schemas' of this component.
很明显,我可以在组件的模块上放置“NO_ERRORS_SCHEMA”,但我不愿意这样做,因为模块中还有其他组件,并且因为我希望未知元素错误检查能够起作用。
那么,我该如何告诉Angular它应该将这个特定组件的内容视为SVG内容?如果这不可能,是否还有其他干净的方法来解决这个问题?