original text:
import { Component, Inject, ReflectiveInjector } from "@angular/core";
import { OverlayContainer } from "@angular/material";
import { environment } from "../environments/environment";
@Component({
selector: "app-root",
templateUrl: "./app.component.html",
styleUrls: ["./app.component.css"]
})
export class AppComponent {
darkTheme = false;
squareState: string;
constructor(private oc: OverlayContainer) {
const injector = ReflectiveInjector.resolveAndCreate([
{ provide: Person, useClass: Person },
{
provide: Address,
useFactory: () => {
if (this.darkTheme) {
return new Address("", "", "", "xx xx ");
} else {
return new Address("", "", "xx", "xx xx ");
}
}
},
{
provide: Id,
useFactory: () => {
return Id.getInstance("idcard");
}
}
]);
const person = injector.get(Person);
console.log(JSON.stringify(person));
}
switchTheme(dark) {
this.darkTheme = dark;
this.oc.themeClass = dark ? "myapp-dark-theme" : null;
}
}
export class Id {
getInstance(type: string): Id {
//
return new Id();
}
}
export class Address {
province: string;
city: string;
district: string;
street: string;
constructor(province, city, district, street) {
this.province = province;
this.city = city;
this.district = district;
this.street = street;
}
}
export class Person {
id: Id;
address: Address;
constructor(@Inject(Id) id, @Inject(Address) address) {
this.id = Id;
this.address = Address;
}
}
ERROR in eaves / Front end / ng2/999/now/0405newNg/my-app/src/app/app.component.ts (30): Property 21): Property "getInstance" does not exist on type" typeof Id".
ERROR in Elux / Front end / ng2/999/now/0405newNg/my-app/src/app/app.component.ts (69): Type 5): Type "typeof Id" is not assignable to type" Id".
Property "getInstance" is missing in type" typeof Id".
ERROR in eaves / Front end / ng2/999/now/0405newNg/my-app/src/app/app.component.ts (70): Type "typeof Address" is not assignable to type" Address".
Property "province" is missing in type" typeof Address".