Angular 无法读取属性';id';在Object.View中未定义的

Angular 无法读取属性';id';在Object.View中未定义的,angular,typescript,jhipster,Angular,Typescript,Jhipster,加载用于编辑角度条目的表单时返回错误 我正在使用JHipster开发一个简单的应用程序,我将弹出对话框变成了一个页面,从那里我很难加载数据进行编辑: 以下是我的完整组件: @Component({ selector: 'jhi-empresa-dialog', templateUrl: './empresa-dialog.component.html' }) export class EmpresaDialogComponent implements OnInit { private sub

加载用于编辑角度条目的表单时返回错误

我正在使用JHipster开发一个简单的应用程序,我将弹出对话框变成了一个页面,从那里我很难加载数据进行编辑:

以下是我的完整组件:

@Component({
selector: 'jhi-empresa-dialog',
templateUrl: './empresa-dialog.component.html'
})

export class EmpresaDialogComponent implements OnInit {

private subscription: Subscription;
private eventSubscriber: Subscription;
codigoCep: string;
empresa: Empresa;
isSaving: boolean;
cep: Cep;
estados: Estado[];
cidades: Cidade[];

constructor(
    public activeModal: NgbActiveModal,
    private alertService: JhiAlertService,
    private empresaService: EmpresaService,
    private cepService: CepService,
    private estadoService: EstadoService,
    private cidadeService: CidadeService,
    private route: ActivatedRoute,
    private router: Router,
    private eventManager: JhiEventManager
) {

}

ngOnInit() {
    this.isSaving = false;
    this.estadoService.query()
        .subscribe((res: ResponseWrapper) => { this.estados = res.json; }, (res: ResponseWrapper) => this.onError(res.json));

    this.subscription = this.route.params.subscribe((params) => {
        if (params['id']) {
            this.load(params['id']);
        }else {
            this.empresa = new Empresa();
        }
    });
    this.registerChangeInEmpresas();

}

load(id) {
    this.empresaService.find(id).subscribe((empresa) => {
        this.empresa = empresa;
        this.buscaCidadePorEstado();
        this.cep = empresa.cep;
        this.codigoCep = this.cep.codigoCep;
    });
}

registerChangeInEmpresas() {
    this.eventSubscriber = this.eventManager.subscribe(
        'empresaListModification',
        (response) => this.load(this.empresa.id)
    );
}

buscaCidadePorEstado() {
    this.cidadeService.cidadesPorEstado(this.empresa.estado.id)
        .subscribe((res: ResponseWrapper) => { this.cidades = res.json; }, (res: ResponseWrapper) => this.onError(res.json));
}

buscaCep() {
    this.cepService.cepPorCodigo(this.codigoCep)
        .subscribe((res: ResponseWrapper) => {
            this.cep = res.json;
            this.empresa.rua = this.cep.rua;
            this.empresa.bairro = this.cep.bairro;
            this.empresa.cep = this.cep;
            this.empresa.estado = this.cep.estado;
            this.buscaCidadePorEstado();
            this.empresa.cidade = this.cep.cidade
        }, (res: ResponseWrapper) => this.onError(res.json));
}

clear() {
    this.activeModal.dismiss('cancel');
}

save() {
    this.isSaving = true;
    if (this.empresa.id !== undefined) {
        this.subscribeToSaveResponse(
            this.empresaService.update(this.empresa));
        this.router.navigate(['/empresa'])
    } else {
        this.subscribeToSaveResponse(
            this.empresaService.create(this.empresa));
        this.router.navigate(['/empresa'])
    }

}

private subscribeToSaveResponse(result: Observable<Empresa>) {
    result.subscribe((res: Empresa) =>
        this.onSaveSuccess(res), (res: Response) => this.onSaveError(res));
}

private onSaveSuccess(result: Empresa) {
    this.eventManager.broadcast({ name: 'empresaListModification', content: 'OK'});
    this.isSaving = false;
    this.activeModal.dismiss(result);
}

private onSaveError(error) {
    try {
        error.json();
    } catch (exception) {
        error.message = error.text();
    }
    this.isSaving = false;
    this.onError(error);
}

private onError(error) {
    this.alertService.error(error.message, null, null);
}

trackCepById(index: number, item: Cep) {
    return item.id;
}

trackEstadoById(index: number, item: Estado) {
    return item.id;
}

trackCidadeById(index: number, item: Cidade) {
    return item.id;
}
}
@组件({
选择器:“jhi empresa对话框”,
templateUrl:“./empresa dialog.component.html”
})
导出类EmpresaDialogComponent实现OnInit{
私人认购:认购;
私人订户:订阅;
codigoCep:字符串;
empresa:empresa;
isSaving:布尔型;
cep:cep;
estados:Estado[];
Cidade:Cidade[];
建造师(
公共活动模式:NgbActiveModal,
私人警报服务:JhiAlertService,
私人经营服务:经营服务,
私人电话服务:电话服务,
私人estadoService:estadoService,
私人设施:私人设施,
专用路由:激活的路由,
专用路由器:路由器,
私有事件管理器:JhiEventManager
) {
}
恩戈尼尼特(){
this.isSaving=false;
this.estadoService.query()
.subscribe((res:ResponseWrapper)=>{this.estados=res.json;},(res:ResponseWrapper)=>this.onError(res.json));
this.subscription=this.route.params.subscripte((params)=>{
if(参数['id']){
this.load(params['id']);
}否则{
this.empresa=新empresa();
}
});
this.registerChangeInImpresas();
}
负载(id){
this.empresaService.find(id).subscribe((empresa)=>{
this.empresa=empresa;
this.buscacidado();
this.cep=empresa.cep;
this.codigoCep=this.cep.codigoCep;
});
}
注册变更管理(){
this.eventSubscriber=this.eventManager.subscribe(
"修改",,
(响应)=>this.load(this.empresa.id)
);
}
布斯卡西达多(){
this.cidadeService.cidaDesprestado(this.empresa.estado.id)
.subscribe((res:ResponseWrapper)=>{this.cidades=res.json;},(res:ResponseWrapper)=>this.onError(res.json));
}
布斯卡普(){
this.cepService.cepprocodigo(this.codigoCep)
.订阅((res:ResponseWrapper)=>{
this.cep=res.json;
this.empresa.rua=this.cep.rua;
this.empresa.bairro=this.cep.bairro;
this.empresa.cep=this.cep;
this.empresa.estado=this.cep.estado;
this.buscacidado();
this.empresa.cidade=this.cep.cidade
},(res:ResponseWrapper)=>this.onError(res.json));
}
清除(){
this.activeModal.discover('cancel');
}
保存(){
this.isSaving=true;
if(this.empresa.id!==未定义){
此.subscribeTosaversponse(
this.empresaService.update(this.empresa));
this.router.navigate(['/empresa']))
}否则{
此.subscribeTosaversponse(
this.empresaService.create(this.empresa));
this.router.navigate(['/empresa']))
}
}
私人SubscribeTosaversponse(结果:可观察){
结果。订阅((res:Empresa)=>
this.onSaveSuccess(res),(res:Response)=>this.onSaveError(res));
}
私人onSaveSuccess(结果:Empresa){
this.eventManager.broadcast({name:'empresaListModification',content:'OK'});
this.isSaving=false;
this.activeModal.discover(结果);
}
私有onSaveError(错误){
试一试{
error.json();
}捕获(例外){
error.message=error.text();
}
this.isSaving=false;
这是一个错误;
}
私有onError(错误){
this.alertService.error(error.message,null,null);
}
trackCepById(索引:编号,项目:Cep){
返回item.id;
}
trackEstadoById(索引:编号,项目:Estado){
返回item.id;
}
trackCidadeById(索引:编号,项目:Cidade){
返回item.id;
}
}

奇怪的是,这些值被加载到表单中并显示在页面上,我甚至可以更改它们,但控制台会多次打印上述错误

我检查了对象,两个变量都不是空的