-4
.subscribe(data=> {
    this.timezones = data;
}

.is data => the same as used in the constructor (private: data) what is the arrow and what does it do ?

export class Xx implements OnInit {

  timezones: Object;

  constructor(private api: ApiService, private data: TimezoneService) { }
  registered: boolean = false;

  ngOnInit() {
    this.data.getTimeZone().subscribe(data=> {
      this.timezones = data;
    });
  }
}
PrakashG
  • 1,625
  • 5
  • 18
  • 27
Johxnn
  • 1
  • 1

1 Answers1

1

.is data => the same as used in the constructor (private: data)
No, it's a variable which stores the response of subscription.

what is the arrow and what does it do?
Here, arrow refer for arrow function which is a new way to declare a function in ES6

This is like

.subscribe(
    function(data) {
        this.timezones = data;
    },
    function(error) {
    },
 )

With arrow function

.subscribe(
    (data) => {
        this.timezones = data;
    },
    (error) => {
    },
 )

OR

.subscribe(
    data => {
        this.timezones = data;
    },
    error => {
    },
 )

I think this article helps you to understand arrow function.

Dhaval
  • 601
  • 5
  • 13