В вашем footer-data
должно быть []
, и может потребоваться changeDetectRef, необходимый для повторной проверки значения после изменений.
Шаг 1 ng new testing
Шаг 2ng g c footer
Шаг 3 In app.module.ts
import { createCustomElement } from '@angular/elements';
import { FooterComponent } from './footer/footer.component';
...
@NgModule({
declarations: [AppComponent, FooterComponent],
imports: [BrowserModule],
providers: [],
bootstrap: [AppComponent],
entryComponents: [FooterComponent],
schemas: [CUSTOM_ELEMENTS_SCHEMA]
})
export class AppModule {
constructor(private injector: Injector) {
const customElement = createCustomElement(FooterComponent, { injector });
customElements.define('some-component', customElement);
}
ngDoBootstrap() { }
}
Шаг 4 In app.component.html
<some-component [data]="footerInputData"></some-component>
Шаг 5 In app.component.ts
...
export class AppComponent {
footerInputData = {"testing": "abc"}
}
Шаг 6 In footer.component.ts
import { Component, OnInit, Input, AfterViewChecked } from '@angular/core';
import { ChangeDetectorRef } from '@angular/core';
@Component({
selector: 'app-footer',
templateUrl: './footer.component.html',
styleUrls: ['./footer.component.scss']
})
export class FooterComponent implements OnInit, AfterViewChecked {
@Input() public data: any;
displayedData = ""
constructor(
private cdRef:ChangeDetectorRef
) { }
ngOnInit() {
}
ngAfterViewChecked() {
this.displayedData = this.data
this.cdRef.detectChanges();
}
}
Шаг 7 In footer.component.html
<p>
{{ displayedData | json }}
</p>