【发布时间】:2020-04-10 03:13:27
【问题描述】:
我是 Angular 的初学者,我想获得一些帮助来解决一个了解起源但我不知道如何解决的问题。所以我想得到一些帮助。首先这里是我的 scr 文件夹的图片:
我的错误位于我的 upgrade.component.ts 中,即:
export class UpgradeComponent implements OnInit {
canclose=false;
@Input() upgrade: Pallier[];
server = "http://localhost:8080/";
@Input() world: World;
@Input() money: number;
@Output() closemodalevent = new EventEmitter<void>();
constructor(private snackBar: MatSnackBar, private service: RestserviceService) {
}
ngOnInit(): void {
}
popMessage(message: string) : void {
this.snackBar.open(message, "", {duration : 2000});
}
closemodal(){
if(this.canclose){
this.closemodalevent.emit();
}else{
this.canclose=true;
}
}
purchaseUpgrade(p: Pallier) {
if (this.world.money > p.seuil) {
this.world.money = this.world.money - p.seuil;
this.world.upgrades.pallier[this.world.upgrades.pallier.indexOf(p)].unlocked = true;
this.popMessage("Achat d'une upgrade de" +p.typeratio);
if (p.idcible == 0) {
this.productsComponent.forEach(prod => prod.calcUpgrade(p));
this.popMessage("Achat d'une upgrade de ");
}
else {
this.productsComponent.forEach(prod => {
if (p.idcible == prod.product.id) {
prod.calcUpgrade(p);
this.popMessage("Achat d'une upgrade de " +p.typeratio);
}
})
}
this.service.putUpgrade(p);
}
}
}
错误很简单:
“UpgradeComponent”类型上不存在属性“productsComponent”。
问题不在于这个属性位于app.component.ts,而是一个@ViewChildren。这是我的app.component.ts:
export class AppComponent {
@ViewChildren(ProductComponent) public productsComponent: QueryList<ProductComponent>;
title = 'AngularProject';
world: World = new World();
server: String;
username: string;
qtmulti = "x1";
modal: string=null;
constructor(private service: RestserviceService, public snackBar: MatSnackBar) {
this.server = service.getServer();
this.username = localStorage.getItem("username");
// Fonction créant un nom de joueur aléatoire si le nom du joueur est et qui sera sauverarder dans le serveur
if (this.username == '') {
this.username = 'Player' + Math.floor(Math.random() * 10000);
localStorage.setItem("username", this.username);
}
this.service.setUser(this.username);
service.getWorld().then(world => { this.world = world; });
}
popMessage(m: string) : void {
this.snackBar.open(m, "", { duration: 2000 });
}
}
我在网上绝对找不到任何东西,我不知道如何解决这个错误......
我提前感谢任何愿意启发我的人。
【问题讨论】:
-
你为什么首先使用 ViewChildren?
-
为了让父母在我解锁时警告所有孩子(产品)
-
angular的版本是什么
-
@malbarmavi Angular 9
-
如果您的问题得到解决,请接受对您有帮助的答案。
标签: angular typescript angular9