I
I
Isaac Clark2018-05-03 22:30:45
Angular
Isaac Clark, 2018-05-03 22:30:45

Why is the data not being updated?

Hello.
Created a service that does a set when a button is clicked

import { Injectable } from '@angular/core';

@Injectable()
export class DataService {
  constructor() { }

  private data;

  setData(data) {
    this.data = data;
  }

  getData() {
    return this.data;
  }
}

in another file, when the button is pressed, the get of this service is called,
this.dataService.getData()
but for some reason the data is not updated .... as it was empty, it remains, despite the fact that if you call it from the console, then everything works fine ....

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander Semenov, 2018-05-04
@w4_alex

...
private _data: <ТИП>;

  set Data(data): void {
    this.data = data;
  }

  get Data(): <ТИП> {
    return this.data;
  }
...

Call like this:
this.dataService.data

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question