在 Angular 组件的模板文件中,我使用带有 ngStyle 的“auto”css 属性,如:
'height' : (some_condition) ? '16px' : auto
组件按预期工作。
但是在 jenkins build 中,我得到的错误是:
Property 'auto' does not exist on type 'MyComponent'.
这个错误的原因是什么?如何摆脱它?
最佳答案
auto
周围没有单引号 '
是导致问题的原因。
Angular 认为 auto
是组件中的一个变量,因为您正在通过绑定(bind)设置 DOM 元素的属性,这有点像这样:[property]=yourVariable
.
要修复它,您可以在组件中使用一个变量来保存字符串 "auto"
,或者您可以简单地键入 'auto'
,使用单引号,在你的模板中。
此外,在为您的应用提供服务时,请尝试使用 --aot 标志 (ng serve --aot
)。这样做应该会提示您出现与 Jenkins 相同的错误,但您不必实际构建。
这个标志很棒,我认为应该尽可能使用它。
关于css - Angular 组件 jenkins 为 'auto' css 属性构建问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57550154/