【发布时间】:2019-02-10 08:50:08
【问题描述】:
我无法在我的界面中调用对象数组,我离开了我的 Angular 界面,然后我必须在 typeScript 中的补码中调用它,但是如果没有数组,我不明白如何调用它一个名字,如果我能把它命名,请解释一下!
Vehiculo-interface.ts
export interface vehiculointerface {
placa?: string,
[index:number]: { Ubicacion ?: string, Nombre ?: string }
id?: string
}
detalles-placa.component.ts
import { Component, OnInit } from '@angular/core';
import { PostService } from 'src/app/post.service';
import { ActivatedRoute,Params } from '@angular/router';
import { vehiculointerface } from '../Models/Vehiculo-interface';
@Component({
selector: 'app-detalles-placa',
templateUrl: './detalles-placa.component.html',
styleUrls: ['./detalles-placa.component.css']
})
export class DetallesPlacaComponent implements OnInit {
constructor(private post: PostService, route: ActivatedRoute) { }
private vehiculo: vehiculointerface = {
placa: "",
{ Ubicacion: "", Nombre: ""},
index() = { Ubicacion: "", Nombre: "" }
}
ngOnInit() { }
}
我无法调用在我的接口[index:number]: {Ubicacion ?: string, Nombre ?: string} 中声明的对象数组我无法调用在我的接口Vehiculo-interface.ts 中声明的对象数组这是我在detalles-placa.component.ts 中需要的对象数组
【问题讨论】:
-
也许其他人可以确认 - 但对我来说,您似乎需要这样的东西... [0]:{Ubicacion: "", Nombre ?: ""} Ubicacion 和 Nombre 都是可选的因为
?..所以你可以有效地用一个,或者另一个,甚至 [0]{} 来代替它。 -
如果你想要一个对象数组,为什么不使用...数组类型?
Array<{Ubicacion?: string, Nombre?: string}>?此外,保持一致并尊重命名约定:类和接口名称以大写字母开头。属性以小写字母开头。 -
@JGFMK 假设这段代码对我有用,但我认为它只给我带来了数组中所有值的一个值,我需要把它全部带来,我对 Angular 来说真的很新,我正在做这个教程:youtube.com/…,在 3:29 分钟,他进行了这个修复,然后在 5:13 调用了该属性,并且不能调用数组,因为它应该是
-
我真的建议您阅读 Angular 文档 - 英雄示例非常有用。然后看看 Youtube 上的免费 Angular 大学视频。如果您喜欢这样并想了解更多信息,他们会提供更多付费内容。我可以彻底推荐他们。但是现在你想在标记中使用像 *ngFor 这样的东西。 angular.io/tutorialyoutube.com/channel/UC3cEGKhg3OERn-ihVsJcb7A/playlists
-
我观看了您发布的视频链接,但没有看到任何看起来像您的索引属性的内容??
标签: angular typescript angular7 loopback