Q: Angular 4 value set in response subscribe is empty when accessed in other function I have a simple subscribe method in which I assign the response to messageIds
messageIds;

this.messageService.subjectPassMessageId.subscribe(data => {
    this.messageIds = data 
    console.log(this.messageIds)         // ['3', '4', '8']
})

But when I access messageIds in other function call, its empty, do I miss something?
addTagToMessage() {
    console.log(this.messageIds)         // []     empty
}

full method:
   ngOnInit() {

  this.messageService.subjectPassMessageId.subscribe(data => {
    this.messageIds = data

    console.log("message ids",this.messageIds)
    })

 }

  addTagToMessage() {
   console.log("The message ids", this.messageIds) [] //empty
  }

html:
  <button (click)="addTagToMessage()">Tag Message</button>


A: messageIds will mostly be getting the value only after executing the addTagToMessage() method. Hope that is the reason

A: As a quick fix this this what I did, but not sure why it should be like this, maybe someone could exmplain:
 messageIds;
 strippedMessageIds;

 this.messageService.subjectPassMessageId.subscribe(data => {
    this.messageIds = data 

    **this.strippedMessageIds = this.messageIds.map(a => a)**

    console.log(this.strippedMessageIds)         // ['3', '4', '8']
  })

And now on this function can access it: 
 addTagToMessage() {
   console.log(this.strippedMessageIds)          // ['3', '4', '8']
 }


A: I did a little example, but I got the expected behaviour, the assignment in this.data = value is working fine, so both of the console.log() statements output the same values.
data;

fakeObservable = new Observable(observer => {
  setTimeout(() => {
    observer.next([1, 2, 3]);
  }, 5000);
});

subscription = this.fakeObservable.subscribe(
  value => {
    this.data = value;
    console.log(value);
  }
);

show() {
  console.log(this.data);
}

What is the type of data? What is the output of console.log(data) inside the subscription?
