2017-02-18 5 views
1

Я получаю следующее сообщение об ошибкеУгловые не может прочитать свойство неопределенного

enter image description here Я новичок в угловой так не в состоянии понять, что это значит. Может кто-нибудь, пожалуйста, объясните мне, что это значит?

import { Component, OnInit, OnDestroy } from '@angular/core'; 
import { ActivatedRoute } from '@angular/router'; 
import { Response } from '@angular/http'; 

import { NgbActiveModal, NgbModalRef } from '@ng-bootstrap/ng-bootstrap'; 
import { EventManager, AlertService, LanguageService } from '../../util'; 

import { DataConfiguration } from './dataconfiguration.model'; 
import { DataConfigurationPopupService } from './dataconfiguration-popup.service'; 
import { DataConfigurationService } from './dataconfiguration.service'; 
@Component({ 
    selector: 'dp-dataconfiguration-dialog', 
    templateUrl: './dataconfiguration-dialog.component.html' 
}) 
export class DataConfigurationDialogComponent implements OnInit { 

    dataConfiguration: DataConfiguration; 
    authorities: any[]; 
    isSaving: boolean; 

    constructor(
     public activeModal: NgbActiveModal, 
     private languageService: LanguageService, 
     private alertService: AlertService, 
     private dataConfigurationService: DataConfigurationService, 
     private eventManager: EventManager 
    ) { 
     this.languageService.setLocations(['dataconfiguration']); 
    } 

    ngOnInit() { 
     this.isSaving = false; 
     this.authorities = ['ROLE_USER', 'ROLE_ADMIN']; 
    } 
    clear() { 
     this.activeModal.dismiss('cancel'); 
    } 

    save() { 
     this.isSaving = true; 
     if (this.dataConfiguration.id !== undefined) { 
      this.dataConfigurationService.update(this.dataConfiguration) 
       .subscribe((res: DataConfiguration) => this.onSaveSuccess(res), (res: Response) => this.onSaveError(res.json())); 
     } else { 
      this.dataConfigurationService.create(this.dataConfiguration) 
       .subscribe((res: DataConfiguration) => this.onSaveSuccess(res), (res: Response) => this.onSaveError(res.json())); 
     } 
    } 

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

    private onSaveError (error) { 
     this.isSaving = false; 
     this.onError(error); 
    } 

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

@Component({ 
    selector: 'dp-dataconfiguration-popup', 
    template: '' 
}) 
export class DataConfigurationPopupComponent implements OnInit, OnDestroy { 

    modalRef: NgbModalRef; 
    routeSub: any; 

    constructor (
     private route: ActivatedRoute, 
     private dataConfigurationPopupService: DataConfigurationPopupService 
    ) {} 

    ngOnInit() { 
     this.routeSub = this.route.params.subscribe(params => { 
      if (params['id']) { 
       this.modalRef = this.dataConfigurationPopupService 
        .open(DataConfigurationDialogComponent, params['id']); 
      } else { 
       this.modalRef = this.dataConfigurationPopupService 
        .open(DataConfigurationDialogComponent); 
      } 

     }); 
    } 

    ngOnDestroy() { 
     this.routeSub.unsubscribe(); 
    } 
} 

HTML

<form name="editForm" role="form" novalidate (ngSubmit)="save()" #editForm="ngForm"> 

    <div class="modal-header"> 
     <button type="button" class="close" data-dismiss="modal" aria-hidden="true" 
       (click)="clear()">&times;</button> 
     <h4 class="modal-title" id="myDataConfigurationLabel" dpTranslate="dataconfiguration.home.createOrEditLabel">Create or edit a DataConfiguration</h4> 
    </div> 
    <div class="modal-body"> 
     <dp-alert-error></dp-alert-error> 
     <div class="form-group" [hidden]="!dataconfiguration.id"> 
      <label for="id" dpTranslate="global.field.id">ID</label> 
      <input type="text" class="form-control" id="id" name="id" 
        [(ngModel)]="dataconfiguration.id" readonly /> 
     </div> 
     <div class="form-group"> 
      <label class="form-control-label" dpTranslate="dataconfiguration.name" for="field_name">Name</label> 
      <input type="text" class="form-control" name="name" id="field_name" 
       [(ngModel)]="dataconfiguration.name" 
      required minlength="3" /> 
      <div [hidden]="!(editForm.controls.name?.dirty && editForm.controls.name?.invalid)"> 
       <small class="form-text text-danger" 
        [hidden]="!editForm.controls.name?.errors?.required" dpTranslate="dataconfiguration.validation.required"> 
        This field is required. 
       </small> 
       <small class="form-text text-danger" 
        [hidden]="!editForm.controls.name?.errors?.minlength" dpTranslate="dataconfiguration.validation.minlength" translateValues="{ min: 3 }"> 
        This field is required to be at least 3 characters. 
       </small> 
      </div> 
     </div> 
    </div> 
    <div class="modal-footer"> 
     <button type="button" class="btn btn-default" data-dismiss="modal" (click)="clear()"> 
      <span class="fa fa-ban"></span>&nbsp;<span dpTranslate="dataconfiguration.action.cancel">Cancel</span> 
     </button> 
     <button type="submit" [disabled]="editForm.form.invalid || isSaving" class="btn btn-primary"> 
      <span class="fa fa-save"></span>&nbsp;<span dpTranslate="dataconfiguration.action.save">Save</span> 
     </button> 
    </div> 
</form> 

index.ts

export * from './tenant.model'; 
export * from './tenant-popup.service'; 
export * from './tenant.service'; 
export * from './tenant-dialog.component'; 
export * from './tenant-delete-dialog.component'; 
export * from './detail/tenant-detail.component'; 
export * from './tenant.component'; 
export * from './tenant.route'; 
export * from './configuration/dataconfiguration.service'; 
export * from './configuration/dataconfiguration-popup.service'; 
export * from './configuration/dataconfiguration-dialog.component'; 
export * from './configuration/dataconfiguration-delete-dialog.component'; 
export * from './configuration/detail/dataconfiguration-detail.component'; 
+1

Посмотрите на файл index.ts в строке 15. Вы пытаетесь прочитать замену свойства для переменной, которая не определена. – mickdev

+0

Можете ли вы разместить свой html? –

+0

обновите код в соответствующих файлах, без которых это невозможно исправить. – Aravind

ответ

0

ОК нашел проблему. В моем файле route.ts я пытался импортировать, используя dataConfiguration, а не с помощью dataconfiguration. Просто капитал C сделал целый ряд различий :))

Это означает, что импорт файлов чувствителен к регистру, поэтому будьте осторожны при импорте. Как-то ошибка должна быть более простой. Я никогда не понимаю ошибки JavaScript.

0

Пожалуйста, поиск замены в целом проекта, я предполагаю, что один из сервисов имеет замену в асинхронной функции, который вызывается в исходном коде выше, но находится где-то в другом месте.

У меня были такие ошибки, когда я использовал это в качестве обещания (возвращенного моей службой). Я только что получил TypeErrors, пока не понял, что мне нужно var other = this; перед возвратом нового обещания и использовать другое значение этого во всех функциях обещания.

+0

Есть ли способ, которым я могу отлаживать и видеть –

+0

AH, я вижу в комментарии выше, вы нашли проблему, пожалуйста, напишите полный ответ, а не только комментарий. – Myonara

Смежные вопросы