我有几个独立的 Web 组件,由 angular 元素组成,我将它们导入一个主组件,它有一个路由器并且是基本应用程序。路线非常简单:
import { Component } from '@angular/core';
import { Router } from "@angular/router";
@Component({
selector: 'example',
template: '<component-one [variable]="toPass" (callback)="onCallback($event)"></component-one>',
styles: []
})
export class ExampleComponent {
public toPass: string = "Hello World!";
constructor(private router: Router) {}
onCallback(event) {
console.log(event);
this.router.navigate(['example-two']);
}
}
组件做他们应该做的事情。
import { Component, Input, OnInit } from '@angular/core';
@Component({
selector: "component-one",
templateUrl: "./component-one.html",
styleUrls: ["./component-one.scss"],
encapsulation: ViewEncapsulation.Emulated,
changeDetection: ChangeDetectionStrategy.OnPush
})
export class ComponentOne implements OnInit {
@Input() variable: string;
@Output() callback = new EventEmitter<any>();
constructor() {}
ngOnInit() {
console.log("Variable: ", this.variable);
}
someRandomButtonClicked() {
callback.emit({ data: "Callback Called" });
}
}
现在,当我启动主应用程序时,一切都按预期显示,回调工作正常,但变量未定义。我的 webcomponents 中的 @Input 声明中是否缺少某些内容?