Q
Q
qwerty252018-07-31 12:04:56
Angular
qwerty25, 2018-07-31 12:04:56

How to get rid of the error "Cannot read property 'attribut_id' of undefined"?

I get this error when loading the page:

ERROR TypeError: Cannot read property 'attribut_id' of undefined
at eval (values.component.ts:132)
at Array.filter ()
at SafeSubscriber.eval [as _next] (values.component.ts:132)
at SafeSubscriber.__tryOrUnsub ( Subscriber.js:243)
at SafeSubscriber.next (Subscriber.js:190)
at Subscriber._next (Subscriber.js:131)
at Subscriber.next (Subscriber.js:95)
at MapSubscriber._next (map.js:85)
at MapSubscriber.Subscriber.next(Subscriber.js:95)
at RefCountSubscriber.Subscriber._next(Subscriber.js:131)

Disappears only after page refresh and then not always. How can you get rid of it completely?
...
export class ValuesComponent implements OnInit {

  values: Array<Value>;
  atributes: Array<Attribute>;
  filteredValues = [];

  constructor(
    public authTokenService: Angular2TokenService, 
    private servAttribute: AttributeService,
    private servValue: ValueService
  ) {
  }

  @Input() attribute: Attribute;

  ngOnInit() {
    this.loadValues();
  }

  private loadValues() {
    let filteredValues;
    if (this.servValue) {
        this.servValue.getValues().subscribe(value => {
            this.values = value;
            this.filteredValues = this.values.filter((value) => value.l_attributs_id == this.attribute.attribut_id);
        });
    }
  }
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vasily Mazhekin, 2018-07-31
@qwerty25

this.servValue.getValues().subscribe(value => {
      if(!this.attribute) { return; }
       ...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question