I am still in the early stages of learning Angular 4 and Redux. I have a component that gets information from the store. It works fine IN THE VIEW. But when I try to access the same information from within the component, I get an object instead of the value.
Here is my component:
import { Component } from '@angular/core';
import { NgRedux, select } from 'ng2-redux';
import { AppState } from '../../reducers/reducer';
import { QuizService } from '../../services/quiz.service';
import { clearQuiz } from '../../actions/actions';
@Component({
selector: 'quiz',
templateUrl: './quiz.component.html',
styleUrls: ['./quiz.component.css']
})
export class Quiz {
constructor(private ngRedux: NgRedux<AppState>, private service: QuizService) {}
@select('currentQuiz') currentQuiz;
@select('quizLength') quizLength;
@select('sessionId') sessionId;
handleClose() {
console.log("CLOSE", this.sessionId )
this.service.deleteSession(this.sessionId)
.subscribe(res => {
this.ngRedux.dispatch(clearQuiz())
})
, error => {
console.error(error);
}
}
}
The "console.log("CLOSE", this.sessionId )" line does not return the value stored in the store. Instead, I get this:
CLOSE AnonymousSubject {_isScalar: false, observers: Array(0), closed: false, isStopped: false, hasError: false, …}
How do you get the data off of these objects within the class? In the view, if I add "| async" after the value, they show up. But I can not get the values from within the actual component class. Help!