- 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积分收益

- 神奇的四哥:发布了悬赏问题函数计算不同地域的是不能用内网吧?预计能赚取 0积分收益

- 神奇的四哥:发布了悬赏问题ARMS可以创建多个应用嘛?预计能赚取 0积分收益

- 神奇的四哥:发布了悬赏问题在ARMS如何申请加入公测呀?预计能赚取 0积分收益

- 神奇的四哥:发布了悬赏问题前端小程序接入这个arms具体是如何接入监控的,这个init方法在哪里进行添加?预计能赚取 0积分收益

- 神奇的四哥:发布了悬赏问题阿里云幻兽帕鲁服务器刚到期,是不是就不能再导出存档了呢?预计能赚取 0积分收益

- 神奇的四哥:发布了悬赏问题阿里云幻兽帕鲁服务器的游戏版本不兼容 尝试更新怎么解决?预计能赚取 0积分收益

- 神奇的四哥:发布了悬赏问题阿里云幻兽帕鲁服务器服务器升级以后 就链接不上了,怎么办?预计能赚取 0积分收益

- 神奇的四哥:发布了悬赏问题阿里云幻兽帕鲁服务器转移以后服务器进不去了,怎么解决?预计能赚取 0积分收益

- 神奇的四哥:发布了悬赏问题阿里云幻兽帕鲁服务器修改参数后游戏进入不了,是什么情况?预计能赚取 0积分收益
- 回到顶部
- 回到顶部
