我已经构建了一个可以导入外部应用程序的 Angular 库。在我的库中存在一个名为“MainComponent”的组件,它有一个用于“objectId”的@Input 变量。
import { Component, Input } from "@angular/core";
import { Router } from "@angular/router";
@Component({
selector: "main-component",
templateUrl: "../templates/app.html",
styleUrls: ["../styles/app.css"],
providers: []
})
export class MainComponent {
@Input() objectId: string;
constructor() {
console.log("MainComponent constructor running!! objectId: " + this.objectId);
// 'objectId' is undefined in the constructor
}
}
当我将库导入另一个项目时,我使用 MainComponent 如下:
<main-component [objectId]="123456"></main-component>
但是,objectId 始终是undefined. 我不确定我做错了什么——因为这是一个定制的 Angular 库,我必须做些什么不同的事情吗?