类型错误:无法读取未定义的 Angular 6 的属性"toString"



我正试图用angular 6构建一个库,但我遇到了一些问题。

在将SoumissionStructComponent添加到我的库模块之前,没有发生任何错误

但一旦我加上它,我就得到了这个

TypeError: Cannot read property 'toString' of undefined
at new Input (C:Userstaha.manarDocumentsworkspaceAdjucation-Ihmnode_modulesng-packagrnode_modulespostcsslibinput.js:53:20)
at parse (C:Userstaha.manarDocumentsworkspaceAdjucation-Ihmnode_modulesng-packagrnode_modulespostcsslibparse.js:13:15)
at new LazyResult (C:Userstaha.manarDocumentsworkspaceAdjucation-Ihmnode_modulesng-packagrnode_modulespostcssliblazy-result.js:60:16)
at Processor.<anonymous> (C:Userstaha.manarDocumentsworkspaceAdjucation-Ihmnode_modulesng-packagrnode_modulespostcsslibprocessor.js:138:12)
...

SoumissionStructComponent.ts

import { Component, OnInit } from '@angular/core';
import { SoumissionService } from './soumission.service';
import { ListElements, ElementList } from './../Common/root-page/model/ElementList';
@Component({
selector: 'app-soumission-struct',
templateUrl: './soumission-struct.component.html',
styleUrls: ['./soumission-struct.component.css']
})
export class SoumissionStructComponent implements OnInit {
listElements: ListElements;
elementsList: ElementList[] = [];
constructor(private soumissionService: SoumissionService) {
soumissionService.getActivatedSoumission().subscribe((r: any) => {
this.listElements = new ListElements();
this.listElements.listElts = [];
if (r) {
this.listElements.listElts.push({ key: r.id, value: r.seanceDate });
}
});
}
ngOnInit() {
}
}

希望我已经清楚地描述了这个问题

您在ng generate之后更改了css->scs吗?如果是,则需要更新styleUrls

与Anthony的答案大致相同,但对我来说,我之所以理解这一点,是因为我更喜欢内联模板和样式,但在使用ng-generate时忘记了包含-s-t标志(尤其是在angular.json中的全局内联设置似乎不固定的lib项目中?(。

在我进行ng生成后,我删除了foo.html和foo.scss文件,以避免在5秒内切换20次时进入恍惚状态。

然后,我将templateUrl更改为template:

foo-works

(注意:将url字符串中的单引号替换为模板的tickmarks(。

然后我经常忘记将styleUrl['fo.scs']更改为style:[``],然后会弹出此错误消息。这是一个很棒的工具发出的非常蹩脚的错误消息,但我认为这与webpack的不透明性有关。

最新更新