账号密码登录
微信安全登录
微信扫描二维码登录

登录后绑定QQ、微信即可实现信息互通

手机验证码登录
找回密码返回
邮箱找回 手机找回
注册账号返回
其他登录方式
分享
  • 收藏
    X
    Property 'getInstance' does not exist on type 'typeof Id'.
    25
    0

    原文为:

    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 E:/前端/ng2/999/now/0405newNg/my-app/src/app/app.component.ts (30,21): Property 'getInstance' does not exist on type 'typeof Id'.

    ERROR in E:/前端/ng2/999/now/0405newNg/my-app/src/app/app.component.ts (69,5): Type 'typeof Id' is not assignable to type 'Id'.
    Property 'getInstance' is missing in type 'typeof Id'.

    ERROR in E:/前端/ng2/999/now/0405newNg/my-app/src/app/app.component.ts (70,5): Type 'typeof Address' is not assignable to type 'Address'.
    Property 'province' is missing in type 'typeof Address'.

    0
    打赏
    收藏
    点击回答
        全部回答
    • 0
    • 烟敛寒林 普通会员 1楼
      502 Bad Gateway

      502 Bad Gateway


      nginx
    更多回答
    扫一扫访问手机版
    • 回到顶部
    • 回到顶部