Angular 指令选择器不适用于外部库中的元素

标签 angular directive

在我的模块中,我使用选择器声明了一个 Angular 指令:

@Directive({
  selector: 'input'
})

尽管它也将应用于在外部模块中声明的组件模板中的输入元素,这些组件在我的指令被声明的同一模块中导入。

所以在我的应用程序中,我有这样的东西:
<my-library-component [(ngModel)]="myModel"></my-library-component>

my-library-component 的模板呈现输入。
在我的模块中,我正在导入声明和导出 my-library-component 的模块。

这是预期的行为吗?

谢谢

最佳答案

这确实是预期的行为,因为在外部模块内,您只能使用在此模块内声明的组件(或组件,它带有一个模块,外部模块导入)

关于Angular 指令选择器不适用于外部库中的元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55705890/

相关文章:

javascript - Angular 7 - 没有具有未指定名称属性的表单控件的值访问器

Angular2 TypeScript 指令错误 TS2345

javascript - 如何优化 canActive Angular 代码

python - 您将如何在 Python 中执行相当于预处理器指令的操作?

javascript - 简单 Ng-Repeat(不重复)场景指令 TemplateUrl

angular - 如何在Angular2中拒绝Promise和处理/捕获错误

node.js - Angular 6 :Property catch does not exist

css - 在 AngularJS 中动态更改指令的类?

javascript - Angularjs 指令 : How to update ng-class in template after change in attribute

c - "precompiler directive""preprocessor directive"