作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试访问名为 disputas
的对象内的属性,但收到以下消息:
[ts] Property 'campanha' does not exist on type 'DisputaComponent[]'
我无法访问 disputas
内的任何属性,我认为这是因为它返回一个 disputas
数组,那么我如何访问每个对象 disputa
在这个数组中?
我想要做的是仅显示具有相同页面 ID 的对象,这是片段代码:
constructor(service: DisputaService, private route:ActivatedRoute,
private router:Router, private campanha_service:FiltroNegociacaoService){
service
.lista()
.subscribe(disputas => {
if (this.disputas.campanha.cliente_id == this.campanha.cliente_id) // this is where I get the message
this.disputas = disputas;
console.log("Disputas: ", disputas);
console.log("Campanha: ", this.campanha);
}, erro => console.log("erro"))
}
如果你们需要的话,这里是完整的代码:
import { Component, OnInit } from '@angular/core';
import {DisputaService} from '../services/disputas.service';
import {FiltroNegociacaoComponent} from '../../../filtra-negociacao/components/filtra-negociacao.component';
import {FiltroNegociacaoService} from '../../../filtra-negociacao/services/filtro-negociacao.service';
import {ActivatedRoute, Routes, RouterModule, Router} from '@angular/router';
@Component({
moduleId: module.id,
selector: 'disputas',
templateUrl: `disputas.component.html`,
providers: [DisputaService, FiltroNegociacaoService]
})
export class DisputaComponent implements OnInit {
public disputas:DisputaComponent[] = [];
public loading = false;
campanhas: FiltroNegociacaoComponent;
campanha:any;
service: DisputaService;
name: string;
proposta_inicial:number;
propostas_realizadas:number = 0;
maximo_propostas:number;
status = {
status_nome: ""
}
id:number;
constructor(service: DisputaService, private route:ActivatedRoute,
private router:Router, private campanha_service:FiltroNegociacaoService){
service
.lista()
.subscribe(disputas => {
if (this.disputas.campanha.cliente_id == this.campanha.cliente_id)
this.disputas = disputas;
console.log("Disputas: ", disputas);
console.log("Campanha: ", this.campanha);
}, erro => console.log("erro"))
}
ngOnInit():void{
this.route.params.subscribe(params =>{
let id = params['id'];
this.campanha_service
.buscaPorId(id)
.subscribe(campanha => {
this.campanha = campanha;
},
erro => console.log(erro));
})
}
提前致谢:)
最佳答案
您正在检索一个 disputas
数组,并尝试查找与 this.campanha
中的 cliente_id
相同的数组。数组本身没有这个属性,你应该过滤数组,然后设置结果:
.subscribe((disputas: DisputaComponent[]) => {
this.disputas = disputas.filter(
disputa => disputa.campanha.client_id === this.campanha.cliente_id
);
}
关于javascript - 类型 'campanha' 上不存在属性 'DisputaComponent[]' - Angular 2,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42905213/
我正在尝试访问名为 disputas 的对象内的属性,但收到以下消息: [ts] Property 'campanha' does not exist on type 'DisputaComponen
我是一名优秀的程序员,十分优秀!