Property 'getInstance' does not exist on type' typeof Id'.

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".

Mar.04,2021

getInstance is an instance property of Id, not a static property. ID.getInstance is of course incorrect, and that's probably what the error prompted by ts means.

what I see incorrect about other places include:

    The injected instance objects used in
  • FactoryProvider should be declared with deps. For more information, please see the document
  • .
  • attributes declared using the @ Inject decorator must be ng-related (component, etc.) or like service, the latest version of @ Injectable, seems to be unnecessary, but the current version is still required.

besides, you may not be familiar with the way ts itself is used. Your ID, Address, Person and other objects use interface to constrain better

.

clipboard.png


ERROR in eaves / Front end / ng2/999/now/0405newNg/my-app/src/app/app.component.ts (30): Property 21 getInstance' does not exist on type 'typeof Id'.
because-"

"
export class Id {
  static getInstance(type: string): Id {
    //
    return new Id();
  }
}

the following two errors are reported because-"id is written as Id, assignment is wrong!"

export class Person {
  id: Id;
  address: Address;
  constructor(@Inject(Id) id, @Inject(Address) address) {
    this.id = id;
    this.address = address;
  }
}

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'.

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1b34e81-2b6cb.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1b34e81-2b6cb.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?