我使用 ng-packagr 从 Angular 5 项目创建了 npm 包,现在我正尝试在新项目中安装该包。我在新项目的 NgModule 中包含包并像这样使用它:
<created-package
[input1]="'value1'"
[input2]="'value2'"
>
</created-package>
该组件呈现,html 和包含的 css 显示,但 @Input 字段(输入 1 和输入 2)未定义。
这是我的 component.ts 的示例:
import {Component, ElementRef, Input, OnInit} from '@angular/core';
@Component({
selector: 'created-package',
templateUrl: './created-package.component.html'
})
export class CreatedPackage implements OnInit {
@Input() value1: any;
@Input() value2: any;
constructor(private router: Router) {
}
ngOnInit() {
console.log(this.value1, this.value2);
}
}
它 console.logs 未定义..
如果有人知道答案,我将非常感谢您的回复!谢谢!