Why am I not getting any Data? Ngrx Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 23, 2019 at 23:30 UTC (7:30pm US/Eastern) Data science time! April 2019 and salary with experience The Ask Question Wizard is Live!What is TypeScript and why would I use it in place of JavaScript?@ngrx/effects Effect Error upgrading to Angular 2 finalAngular 2 Routing Does Not Work When Deployed to Http ServerAngular4 multiple modules issueerror TS2707 : Generic type 'MatDialogRef<T,R>' requiers between 1 and 2 argumentsrouting navigate method not redirecting to targeted componentImporting a module implemented in ngrx and re-using effect with overriden service$Injector Error on Angular Upgrade from 1.6.6 to 6Core module component and Shared module implementation in angular

Are Flameskulls resistant to magical piercing damage?

A journey... into the MIND

How to produce a PS1 prompt in bash or ksh93 similar to tcsh

Why doesn't the university give past final exams' answers?

Why not use the yoke to control yaw, as well as pitch and roll?

Sorting the characters in a utf-16 string in java

What is the ongoing value of the Kanban board to the developers as opposed to management

Can this water damage be explained by lack of gutters and grading issues?

tabularx column has extra padding at right?

Does traveling In The United States require a passport or can I use my green card if not a US citizen?

Can I take recommendation from someone I met at a conference?

Does using the Inspiration rules for character defects encourage My Guy Syndrome?

Married in secret, can marital status in passport be changed at a later date?

Etymology of 見舞い

Does Prince Arnaud cause someone holding the Princess to lose?

How can I introduce the names of fantasy creatures to the reader?

How to keep bees out of canned beverages?

Unix AIX passing variable and arguments to expect and spawn

Is there a verb for listening stealthily?

Like totally amazing interchangeable sister outfit accessory swapping or whatever

Is Bran literally the world's memory?

What could prevent concentrated local exploration?

How to leave only the following strings?

Protagonist's race is hidden - should I reveal it?



Why am I not getting any Data? Ngrx



Announcing the arrival of Valued Associate #679: Cesar Manara
Planned maintenance scheduled April 23, 2019 at 23:30 UTC (7:30pm US/Eastern)
Data science time! April 2019 and salary with experience
The Ask Question Wizard is Live!What is TypeScript and why would I use it in place of JavaScript?@ngrx/effects Effect Error upgrading to Angular 2 finalAngular 2 Routing Does Not Work When Deployed to Http ServerAngular4 multiple modules issueerror TS2707 : Generic type 'MatDialogRef<T,R>' requiers between 1 and 2 argumentsrouting navigate method not redirecting to targeted componentImporting a module implemented in ngrx and re-using effect with overriden service$Injector Error on Angular Upgrade from 1.6.6 to 6Core module component and Shared module implementation in angular



.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;








5















I tried to implement Ngrx into my Angular Application, but sadly haven't been able to retrieve any data. Any help is appreciated!



What I'm trying to do in the property.component.ts is to get all the data when the component gets instantiated and just display the data in the property.component.html.



property.component.ts



import Component, OnInit from '@angular/core';
import select, Store from '@ngrx/store';

import Router from '@angular/router';

@Component(
selector: 'app-property',
templateUrl: './property.component.html',
styleUrls: ['./property.component.css']
)
export class PropertyComponent implements OnInit

properties$ = this._store.pipe(select('properties'));

constructor(private _store: Store<any>, private _router: Router)

ngOnInit()
this._store.dispatch(
type: '[Property] Get Properties'
);
console.log(this.properties$);


navigateToProperty(id: number)
this._router.navigate(['property', id]);





property.component.html



<p>test</p>
<p> async</p>


property.service.ts



 import Injectable from '@angular/core';
import HttpClient, HttpHeaders from '@angular/common/http';
import Observable from 'rxjs';
import PropertyModel from '../models/property.model';

@Injectable(
providedIn: 'root'
)
export class PropertyService
propertiesUrl = 'someapi';
private httpOptions =
headers: new HttpHeaders(
'Content-Type': 'application/json'
)
;

constructor(private http: HttpClient)

getProperties(): Observable<PropertyModel[]>
return this.http.get<PropertyModel[]>(this.propertiesUrl, this.httpOptions);




property.actions.ts



import Action from '@ngrx/store';
import PropertyModel from '../../models/property.model';


export const GET_PROPERTIES = '[Property] Get Properties';
export const GET_PROPERTIES_SUCCESS = '[Property] Get Properties Success';
export const SEARCH_PROPERTY = '[Property] Get Property';
export const SEARCH_PROPERTY_SUCCESS = '[Property] Get Property Success';

export class GetProperties implements Action
public readonly type = GET_PROPERTIES;
constructor(public retrievedProperties: PropertyModel[])


export class GetPropertiesSuccess implements Action
public readonly type = GET_PROPERTIES_SUCCESS;
constructor(public retrievedProperties: PropertyModel[])


export class GetProperty implements Action
public readonly type = SEARCH_PROPERTY;
constructor(public searchId: string)


export type PropertyActions = GetProperties | GetPropertiesSuccess | GetProperty;


property.effects.ts



import Injectable from '@angular/core';
import Actions, Effect, ofType from '@ngrx/effects';

import GET_PROPERTIES, PropertyActions from '../actions/property.actions';
import PropertyService from '../../services/property.service';
import mapTo from 'rxjs/operators';


@Injectable()

export class PropertyEffects

@Effect()
getProperties$ = this.actions$.pipe(
ofType<PropertyActions>(GET_PROPERTIES),
mapTo(this.propertyService.getProperties())
);

constructor(private actions$: Actions, private propertyService: PropertyService)




and finally my property.reducers.ts



import GET_PROPERTIES, GET_PROPERTIES_SUCCESS, PropertyActions from '../actions/property.actions';
import PropertyModel from '../../models/property.model';

export function propertyReducer(properties: PropertyModel[] = [], action: PropertyActions): PropertyModel[]
switch (action.type)
case GET_PROPERTIES:
return [...action.retrievedProperties];

default:
return properties;





app.module.ts



import BrowserModule from '@angular/platform-browser';
import NgModule from '@angular/core';

import AppComponent from './app.component';
import CustomerComponent from './customer/customer.component';
import HttpClientModule from '@angular/common/http';
import CustomMaterialModule from './custom.material.module';
import RouterModule, Routes from '@angular/router';
import BrowserAnimationsModule from '@angular/platform-browser/animations';
import StoreModule from '@ngrx/store';
import PropertyComponent from './property/property.component';
import propertyReducer from './store/reducers/property.reducers';

const appRoutes: Routes = [

path: 'customers',
component: CustomerComponent,
data: title: 'Customer List'
,

path: 'property',
component: PropertyComponent,
data: title: 'Property List'
,

path: '', // General redirect
component: CustomerComponent,
pathMatch: 'full'

];

@NgModule(
declarations: [
AppComponent,
CustomerComponent,
PropertyComponent
],
imports: [
BrowserModule,
RouterModule.forRoot(appRoutes),
HttpClientModule,
BrowserAnimationsModule,
CustomMaterialModule,
StoreModule.forRoot(propertyReducer)
],
providers: [],
bootstrap: [AppComponent]
)
export class AppModule









share|improve this question



















  • 2





    Your effect should dispatch a success and then map the returned data to your state. Right now, you are calling your service but the returned data is not map to your state because the reducer is called before the effect

    – ukn
    Mar 22 at 14:30












  • How is my reducer being called before my effect?

    – BlueScoreMan
    Mar 22 at 14:39

















5















I tried to implement Ngrx into my Angular Application, but sadly haven't been able to retrieve any data. Any help is appreciated!



What I'm trying to do in the property.component.ts is to get all the data when the component gets instantiated and just display the data in the property.component.html.



property.component.ts



import Component, OnInit from '@angular/core';
import select, Store from '@ngrx/store';

import Router from '@angular/router';

@Component(
selector: 'app-property',
templateUrl: './property.component.html',
styleUrls: ['./property.component.css']
)
export class PropertyComponent implements OnInit

properties$ = this._store.pipe(select('properties'));

constructor(private _store: Store<any>, private _router: Router)

ngOnInit()
this._store.dispatch(
type: '[Property] Get Properties'
);
console.log(this.properties$);


navigateToProperty(id: number)
this._router.navigate(['property', id]);





property.component.html



<p>test</p>
<p> async</p>


property.service.ts



 import Injectable from '@angular/core';
import HttpClient, HttpHeaders from '@angular/common/http';
import Observable from 'rxjs';
import PropertyModel from '../models/property.model';

@Injectable(
providedIn: 'root'
)
export class PropertyService
propertiesUrl = 'someapi';
private httpOptions =
headers: new HttpHeaders(
'Content-Type': 'application/json'
)
;

constructor(private http: HttpClient)

getProperties(): Observable<PropertyModel[]>
return this.http.get<PropertyModel[]>(this.propertiesUrl, this.httpOptions);




property.actions.ts



import Action from '@ngrx/store';
import PropertyModel from '../../models/property.model';


export const GET_PROPERTIES = '[Property] Get Properties';
export const GET_PROPERTIES_SUCCESS = '[Property] Get Properties Success';
export const SEARCH_PROPERTY = '[Property] Get Property';
export const SEARCH_PROPERTY_SUCCESS = '[Property] Get Property Success';

export class GetProperties implements Action
public readonly type = GET_PROPERTIES;
constructor(public retrievedProperties: PropertyModel[])


export class GetPropertiesSuccess implements Action
public readonly type = GET_PROPERTIES_SUCCESS;
constructor(public retrievedProperties: PropertyModel[])


export class GetProperty implements Action
public readonly type = SEARCH_PROPERTY;
constructor(public searchId: string)


export type PropertyActions = GetProperties | GetPropertiesSuccess | GetProperty;


property.effects.ts



import Injectable from '@angular/core';
import Actions, Effect, ofType from '@ngrx/effects';

import GET_PROPERTIES, PropertyActions from '../actions/property.actions';
import PropertyService from '../../services/property.service';
import mapTo from 'rxjs/operators';


@Injectable()

export class PropertyEffects

@Effect()
getProperties$ = this.actions$.pipe(
ofType<PropertyActions>(GET_PROPERTIES),
mapTo(this.propertyService.getProperties())
);

constructor(private actions$: Actions, private propertyService: PropertyService)




and finally my property.reducers.ts



import GET_PROPERTIES, GET_PROPERTIES_SUCCESS, PropertyActions from '../actions/property.actions';
import PropertyModel from '../../models/property.model';

export function propertyReducer(properties: PropertyModel[] = [], action: PropertyActions): PropertyModel[]
switch (action.type)
case GET_PROPERTIES:
return [...action.retrievedProperties];

default:
return properties;





app.module.ts



import BrowserModule from '@angular/platform-browser';
import NgModule from '@angular/core';

import AppComponent from './app.component';
import CustomerComponent from './customer/customer.component';
import HttpClientModule from '@angular/common/http';
import CustomMaterialModule from './custom.material.module';
import RouterModule, Routes from '@angular/router';
import BrowserAnimationsModule from '@angular/platform-browser/animations';
import StoreModule from '@ngrx/store';
import PropertyComponent from './property/property.component';
import propertyReducer from './store/reducers/property.reducers';

const appRoutes: Routes = [

path: 'customers',
component: CustomerComponent,
data: title: 'Customer List'
,

path: 'property',
component: PropertyComponent,
data: title: 'Property List'
,

path: '', // General redirect
component: CustomerComponent,
pathMatch: 'full'

];

@NgModule(
declarations: [
AppComponent,
CustomerComponent,
PropertyComponent
],
imports: [
BrowserModule,
RouterModule.forRoot(appRoutes),
HttpClientModule,
BrowserAnimationsModule,
CustomMaterialModule,
StoreModule.forRoot(propertyReducer)
],
providers: [],
bootstrap: [AppComponent]
)
export class AppModule









share|improve this question



















  • 2





    Your effect should dispatch a success and then map the returned data to your state. Right now, you are calling your service but the returned data is not map to your state because the reducer is called before the effect

    – ukn
    Mar 22 at 14:30












  • How is my reducer being called before my effect?

    – BlueScoreMan
    Mar 22 at 14:39













5












5








5








I tried to implement Ngrx into my Angular Application, but sadly haven't been able to retrieve any data. Any help is appreciated!



What I'm trying to do in the property.component.ts is to get all the data when the component gets instantiated and just display the data in the property.component.html.



property.component.ts



import Component, OnInit from '@angular/core';
import select, Store from '@ngrx/store';

import Router from '@angular/router';

@Component(
selector: 'app-property',
templateUrl: './property.component.html',
styleUrls: ['./property.component.css']
)
export class PropertyComponent implements OnInit

properties$ = this._store.pipe(select('properties'));

constructor(private _store: Store<any>, private _router: Router)

ngOnInit()
this._store.dispatch(
type: '[Property] Get Properties'
);
console.log(this.properties$);


navigateToProperty(id: number)
this._router.navigate(['property', id]);





property.component.html



<p>test</p>
<p> async</p>


property.service.ts



 import Injectable from '@angular/core';
import HttpClient, HttpHeaders from '@angular/common/http';
import Observable from 'rxjs';
import PropertyModel from '../models/property.model';

@Injectable(
providedIn: 'root'
)
export class PropertyService
propertiesUrl = 'someapi';
private httpOptions =
headers: new HttpHeaders(
'Content-Type': 'application/json'
)
;

constructor(private http: HttpClient)

getProperties(): Observable<PropertyModel[]>
return this.http.get<PropertyModel[]>(this.propertiesUrl, this.httpOptions);




property.actions.ts



import Action from '@ngrx/store';
import PropertyModel from '../../models/property.model';


export const GET_PROPERTIES = '[Property] Get Properties';
export const GET_PROPERTIES_SUCCESS = '[Property] Get Properties Success';
export const SEARCH_PROPERTY = '[Property] Get Property';
export const SEARCH_PROPERTY_SUCCESS = '[Property] Get Property Success';

export class GetProperties implements Action
public readonly type = GET_PROPERTIES;
constructor(public retrievedProperties: PropertyModel[])


export class GetPropertiesSuccess implements Action
public readonly type = GET_PROPERTIES_SUCCESS;
constructor(public retrievedProperties: PropertyModel[])


export class GetProperty implements Action
public readonly type = SEARCH_PROPERTY;
constructor(public searchId: string)


export type PropertyActions = GetProperties | GetPropertiesSuccess | GetProperty;


property.effects.ts



import Injectable from '@angular/core';
import Actions, Effect, ofType from '@ngrx/effects';

import GET_PROPERTIES, PropertyActions from '../actions/property.actions';
import PropertyService from '../../services/property.service';
import mapTo from 'rxjs/operators';


@Injectable()

export class PropertyEffects

@Effect()
getProperties$ = this.actions$.pipe(
ofType<PropertyActions>(GET_PROPERTIES),
mapTo(this.propertyService.getProperties())
);

constructor(private actions$: Actions, private propertyService: PropertyService)




and finally my property.reducers.ts



import GET_PROPERTIES, GET_PROPERTIES_SUCCESS, PropertyActions from '../actions/property.actions';
import PropertyModel from '../../models/property.model';

export function propertyReducer(properties: PropertyModel[] = [], action: PropertyActions): PropertyModel[]
switch (action.type)
case GET_PROPERTIES:
return [...action.retrievedProperties];

default:
return properties;





app.module.ts



import BrowserModule from '@angular/platform-browser';
import NgModule from '@angular/core';

import AppComponent from './app.component';
import CustomerComponent from './customer/customer.component';
import HttpClientModule from '@angular/common/http';
import CustomMaterialModule from './custom.material.module';
import RouterModule, Routes from '@angular/router';
import BrowserAnimationsModule from '@angular/platform-browser/animations';
import StoreModule from '@ngrx/store';
import PropertyComponent from './property/property.component';
import propertyReducer from './store/reducers/property.reducers';

const appRoutes: Routes = [

path: 'customers',
component: CustomerComponent,
data: title: 'Customer List'
,

path: 'property',
component: PropertyComponent,
data: title: 'Property List'
,

path: '', // General redirect
component: CustomerComponent,
pathMatch: 'full'

];

@NgModule(
declarations: [
AppComponent,
CustomerComponent,
PropertyComponent
],
imports: [
BrowserModule,
RouterModule.forRoot(appRoutes),
HttpClientModule,
BrowserAnimationsModule,
CustomMaterialModule,
StoreModule.forRoot(propertyReducer)
],
providers: [],
bootstrap: [AppComponent]
)
export class AppModule









share|improve this question
















I tried to implement Ngrx into my Angular Application, but sadly haven't been able to retrieve any data. Any help is appreciated!



What I'm trying to do in the property.component.ts is to get all the data when the component gets instantiated and just display the data in the property.component.html.



property.component.ts



import Component, OnInit from '@angular/core';
import select, Store from '@ngrx/store';

import Router from '@angular/router';

@Component(
selector: 'app-property',
templateUrl: './property.component.html',
styleUrls: ['./property.component.css']
)
export class PropertyComponent implements OnInit

properties$ = this._store.pipe(select('properties'));

constructor(private _store: Store<any>, private _router: Router)

ngOnInit()
this._store.dispatch(
type: '[Property] Get Properties'
);
console.log(this.properties$);


navigateToProperty(id: number)
this._router.navigate(['property', id]);





property.component.html



<p>test</p>
<p> async</p>


property.service.ts



 import Injectable from '@angular/core';
import HttpClient, HttpHeaders from '@angular/common/http';
import Observable from 'rxjs';
import PropertyModel from '../models/property.model';

@Injectable(
providedIn: 'root'
)
export class PropertyService
propertiesUrl = 'someapi';
private httpOptions =
headers: new HttpHeaders(
'Content-Type': 'application/json'
)
;

constructor(private http: HttpClient)

getProperties(): Observable<PropertyModel[]>
return this.http.get<PropertyModel[]>(this.propertiesUrl, this.httpOptions);




property.actions.ts



import Action from '@ngrx/store';
import PropertyModel from '../../models/property.model';


export const GET_PROPERTIES = '[Property] Get Properties';
export const GET_PROPERTIES_SUCCESS = '[Property] Get Properties Success';
export const SEARCH_PROPERTY = '[Property] Get Property';
export const SEARCH_PROPERTY_SUCCESS = '[Property] Get Property Success';

export class GetProperties implements Action
public readonly type = GET_PROPERTIES;
constructor(public retrievedProperties: PropertyModel[])


export class GetPropertiesSuccess implements Action
public readonly type = GET_PROPERTIES_SUCCESS;
constructor(public retrievedProperties: PropertyModel[])


export class GetProperty implements Action
public readonly type = SEARCH_PROPERTY;
constructor(public searchId: string)


export type PropertyActions = GetProperties | GetPropertiesSuccess | GetProperty;


property.effects.ts



import Injectable from '@angular/core';
import Actions, Effect, ofType from '@ngrx/effects';

import GET_PROPERTIES, PropertyActions from '../actions/property.actions';
import PropertyService from '../../services/property.service';
import mapTo from 'rxjs/operators';


@Injectable()

export class PropertyEffects

@Effect()
getProperties$ = this.actions$.pipe(
ofType<PropertyActions>(GET_PROPERTIES),
mapTo(this.propertyService.getProperties())
);

constructor(private actions$: Actions, private propertyService: PropertyService)




and finally my property.reducers.ts



import GET_PROPERTIES, GET_PROPERTIES_SUCCESS, PropertyActions from '../actions/property.actions';
import PropertyModel from '../../models/property.model';

export function propertyReducer(properties: PropertyModel[] = [], action: PropertyActions): PropertyModel[]
switch (action.type)
case GET_PROPERTIES:
return [...action.retrievedProperties];

default:
return properties;





app.module.ts



import BrowserModule from '@angular/platform-browser';
import NgModule from '@angular/core';

import AppComponent from './app.component';
import CustomerComponent from './customer/customer.component';
import HttpClientModule from '@angular/common/http';
import CustomMaterialModule from './custom.material.module';
import RouterModule, Routes from '@angular/router';
import BrowserAnimationsModule from '@angular/platform-browser/animations';
import StoreModule from '@ngrx/store';
import PropertyComponent from './property/property.component';
import propertyReducer from './store/reducers/property.reducers';

const appRoutes: Routes = [

path: 'customers',
component: CustomerComponent,
data: title: 'Customer List'
,

path: 'property',
component: PropertyComponent,
data: title: 'Property List'
,

path: '', // General redirect
component: CustomerComponent,
pathMatch: 'full'

];

@NgModule(
declarations: [
AppComponent,
CustomerComponent,
PropertyComponent
],
imports: [
BrowserModule,
RouterModule.forRoot(appRoutes),
HttpClientModule,
BrowserAnimationsModule,
CustomMaterialModule,
StoreModule.forRoot(propertyReducer)
],
providers: [],
bootstrap: [AppComponent]
)
export class AppModule






angular typescript web frontend ngrx






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Mar 22 at 14:47







BlueScoreMan

















asked Mar 22 at 14:11









BlueScoreManBlueScoreMan

180113




180113







  • 2





    Your effect should dispatch a success and then map the returned data to your state. Right now, you are calling your service but the returned data is not map to your state because the reducer is called before the effect

    – ukn
    Mar 22 at 14:30












  • How is my reducer being called before my effect?

    – BlueScoreMan
    Mar 22 at 14:39












  • 2





    Your effect should dispatch a success and then map the returned data to your state. Right now, you are calling your service but the returned data is not map to your state because the reducer is called before the effect

    – ukn
    Mar 22 at 14:30












  • How is my reducer being called before my effect?

    – BlueScoreMan
    Mar 22 at 14:39







2




2





Your effect should dispatch a success and then map the returned data to your state. Right now, you are calling your service but the returned data is not map to your state because the reducer is called before the effect

– ukn
Mar 22 at 14:30






Your effect should dispatch a success and then map the returned data to your state. Right now, you are calling your service but the returned data is not map to your state because the reducer is called before the effect

– ukn
Mar 22 at 14:30














How is my reducer being called before my effect?

– BlueScoreMan
Mar 22 at 14:39





How is my reducer being called before my effect?

– BlueScoreMan
Mar 22 at 14:39












1 Answer
1






active

oldest

votes


















4














Working stackblitz example



Don't forget to dispatch success and error actions and to reduce them.
Also change mapTo to switchMapTo



@Effect()
getProperties$ = this.actions$.pipe(
ofType<PropertyActions>(GET_PROPERTIES),
switchMapTo(this.propertyService.getProperties().pipe(
map(props => new GetPropertiesSuccess(props)),
// catch error here
// catchError(error => of(new GetPropertiesError(error))),
),
),

);


In your reducer, listen to correct type



case GET_PROPERTIES_SUCCESS: 
return [...action.retrievedProperties];



For clarity remove retrievedProperties from GetProperties - the action does not have any retrieved props. The success action should be used to pass them.



In your app module change the reducer setup and don't forget to import the effects:



imports: [
BrowserModule,
RouterModule.forRoot(appRoutes),
HttpClientModule,
BrowserAnimationsModule,
// change this
StoreModule.forRoot(properties: propertyReducer),
// this is needed
EffectsModule.forRoot([PropertyEffects])
],


Optional: In your PropertyComponent change the the dispatched action to the instance of the GetProperties class. That's how it should be used.



 this._store.dispatch(new GetProperties());





share|improve this answer

























  • I tried your code, but localhost seems to be just loading constantly.

    – BlueScoreMan
    Mar 22 at 14:39











  • I had a wrong ) typo.

    – kvetis
    Mar 22 at 14:41






  • 1





    stackblitz.com/edit/angular-lqxshw

    – BlueScoreMan
    Mar 22 at 15:05






  • 3





    Well donw the rabbit hole i go there are more and more errors in your code. You should go and try an NGRx tutorial. There are many misconceptions here.

    – kvetis
    Mar 22 at 15:22






  • 1





    I got that working. I expanded my answer so it has everything. Good luck coding. stackblitz.com/edit/angular-d5aypp

    – kvetis
    Mar 22 at 15:30












Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55301479%2fwhy-am-i-not-getting-any-data-ngrx%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









4














Working stackblitz example



Don't forget to dispatch success and error actions and to reduce them.
Also change mapTo to switchMapTo



@Effect()
getProperties$ = this.actions$.pipe(
ofType<PropertyActions>(GET_PROPERTIES),
switchMapTo(this.propertyService.getProperties().pipe(
map(props => new GetPropertiesSuccess(props)),
// catch error here
// catchError(error => of(new GetPropertiesError(error))),
),
),

);


In your reducer, listen to correct type



case GET_PROPERTIES_SUCCESS: 
return [...action.retrievedProperties];



For clarity remove retrievedProperties from GetProperties - the action does not have any retrieved props. The success action should be used to pass them.



In your app module change the reducer setup and don't forget to import the effects:



imports: [
BrowserModule,
RouterModule.forRoot(appRoutes),
HttpClientModule,
BrowserAnimationsModule,
// change this
StoreModule.forRoot(properties: propertyReducer),
// this is needed
EffectsModule.forRoot([PropertyEffects])
],


Optional: In your PropertyComponent change the the dispatched action to the instance of the GetProperties class. That's how it should be used.



 this._store.dispatch(new GetProperties());





share|improve this answer

























  • I tried your code, but localhost seems to be just loading constantly.

    – BlueScoreMan
    Mar 22 at 14:39











  • I had a wrong ) typo.

    – kvetis
    Mar 22 at 14:41






  • 1





    stackblitz.com/edit/angular-lqxshw

    – BlueScoreMan
    Mar 22 at 15:05






  • 3





    Well donw the rabbit hole i go there are more and more errors in your code. You should go and try an NGRx tutorial. There are many misconceptions here.

    – kvetis
    Mar 22 at 15:22






  • 1





    I got that working. I expanded my answer so it has everything. Good luck coding. stackblitz.com/edit/angular-d5aypp

    – kvetis
    Mar 22 at 15:30
















4














Working stackblitz example



Don't forget to dispatch success and error actions and to reduce them.
Also change mapTo to switchMapTo



@Effect()
getProperties$ = this.actions$.pipe(
ofType<PropertyActions>(GET_PROPERTIES),
switchMapTo(this.propertyService.getProperties().pipe(
map(props => new GetPropertiesSuccess(props)),
// catch error here
// catchError(error => of(new GetPropertiesError(error))),
),
),

);


In your reducer, listen to correct type



case GET_PROPERTIES_SUCCESS: 
return [...action.retrievedProperties];



For clarity remove retrievedProperties from GetProperties - the action does not have any retrieved props. The success action should be used to pass them.



In your app module change the reducer setup and don't forget to import the effects:



imports: [
BrowserModule,
RouterModule.forRoot(appRoutes),
HttpClientModule,
BrowserAnimationsModule,
// change this
StoreModule.forRoot(properties: propertyReducer),
// this is needed
EffectsModule.forRoot([PropertyEffects])
],


Optional: In your PropertyComponent change the the dispatched action to the instance of the GetProperties class. That's how it should be used.



 this._store.dispatch(new GetProperties());





share|improve this answer

























  • I tried your code, but localhost seems to be just loading constantly.

    – BlueScoreMan
    Mar 22 at 14:39











  • I had a wrong ) typo.

    – kvetis
    Mar 22 at 14:41






  • 1





    stackblitz.com/edit/angular-lqxshw

    – BlueScoreMan
    Mar 22 at 15:05






  • 3





    Well donw the rabbit hole i go there are more and more errors in your code. You should go and try an NGRx tutorial. There are many misconceptions here.

    – kvetis
    Mar 22 at 15:22






  • 1





    I got that working. I expanded my answer so it has everything. Good luck coding. stackblitz.com/edit/angular-d5aypp

    – kvetis
    Mar 22 at 15:30














4












4








4







Working stackblitz example



Don't forget to dispatch success and error actions and to reduce them.
Also change mapTo to switchMapTo



@Effect()
getProperties$ = this.actions$.pipe(
ofType<PropertyActions>(GET_PROPERTIES),
switchMapTo(this.propertyService.getProperties().pipe(
map(props => new GetPropertiesSuccess(props)),
// catch error here
// catchError(error => of(new GetPropertiesError(error))),
),
),

);


In your reducer, listen to correct type



case GET_PROPERTIES_SUCCESS: 
return [...action.retrievedProperties];



For clarity remove retrievedProperties from GetProperties - the action does not have any retrieved props. The success action should be used to pass them.



In your app module change the reducer setup and don't forget to import the effects:



imports: [
BrowserModule,
RouterModule.forRoot(appRoutes),
HttpClientModule,
BrowserAnimationsModule,
// change this
StoreModule.forRoot(properties: propertyReducer),
// this is needed
EffectsModule.forRoot([PropertyEffects])
],


Optional: In your PropertyComponent change the the dispatched action to the instance of the GetProperties class. That's how it should be used.



 this._store.dispatch(new GetProperties());





share|improve this answer















Working stackblitz example



Don't forget to dispatch success and error actions and to reduce them.
Also change mapTo to switchMapTo



@Effect()
getProperties$ = this.actions$.pipe(
ofType<PropertyActions>(GET_PROPERTIES),
switchMapTo(this.propertyService.getProperties().pipe(
map(props => new GetPropertiesSuccess(props)),
// catch error here
// catchError(error => of(new GetPropertiesError(error))),
),
),

);


In your reducer, listen to correct type



case GET_PROPERTIES_SUCCESS: 
return [...action.retrievedProperties];



For clarity remove retrievedProperties from GetProperties - the action does not have any retrieved props. The success action should be used to pass them.



In your app module change the reducer setup and don't forget to import the effects:



imports: [
BrowserModule,
RouterModule.forRoot(appRoutes),
HttpClientModule,
BrowserAnimationsModule,
// change this
StoreModule.forRoot(properties: propertyReducer),
// this is needed
EffectsModule.forRoot([PropertyEffects])
],


Optional: In your PropertyComponent change the the dispatched action to the instance of the GetProperties class. That's how it should be used.



 this._store.dispatch(new GetProperties());






share|improve this answer














share|improve this answer



share|improve this answer








edited Mar 22 at 15:53

























answered Mar 22 at 14:28









kvetiskvetis

1,79411328




1,79411328












  • I tried your code, but localhost seems to be just loading constantly.

    – BlueScoreMan
    Mar 22 at 14:39











  • I had a wrong ) typo.

    – kvetis
    Mar 22 at 14:41






  • 1





    stackblitz.com/edit/angular-lqxshw

    – BlueScoreMan
    Mar 22 at 15:05






  • 3





    Well donw the rabbit hole i go there are more and more errors in your code. You should go and try an NGRx tutorial. There are many misconceptions here.

    – kvetis
    Mar 22 at 15:22






  • 1





    I got that working. I expanded my answer so it has everything. Good luck coding. stackblitz.com/edit/angular-d5aypp

    – kvetis
    Mar 22 at 15:30


















  • I tried your code, but localhost seems to be just loading constantly.

    – BlueScoreMan
    Mar 22 at 14:39











  • I had a wrong ) typo.

    – kvetis
    Mar 22 at 14:41






  • 1





    stackblitz.com/edit/angular-lqxshw

    – BlueScoreMan
    Mar 22 at 15:05






  • 3





    Well donw the rabbit hole i go there are more and more errors in your code. You should go and try an NGRx tutorial. There are many misconceptions here.

    – kvetis
    Mar 22 at 15:22






  • 1





    I got that working. I expanded my answer so it has everything. Good luck coding. stackblitz.com/edit/angular-d5aypp

    – kvetis
    Mar 22 at 15:30

















I tried your code, but localhost seems to be just loading constantly.

– BlueScoreMan
Mar 22 at 14:39





I tried your code, but localhost seems to be just loading constantly.

– BlueScoreMan
Mar 22 at 14:39













I had a wrong ) typo.

– kvetis
Mar 22 at 14:41





I had a wrong ) typo.

– kvetis
Mar 22 at 14:41




1




1





stackblitz.com/edit/angular-lqxshw

– BlueScoreMan
Mar 22 at 15:05





stackblitz.com/edit/angular-lqxshw

– BlueScoreMan
Mar 22 at 15:05




3




3





Well donw the rabbit hole i go there are more and more errors in your code. You should go and try an NGRx tutorial. There are many misconceptions here.

– kvetis
Mar 22 at 15:22





Well donw the rabbit hole i go there are more and more errors in your code. You should go and try an NGRx tutorial. There are many misconceptions here.

– kvetis
Mar 22 at 15:22




1




1





I got that working. I expanded my answer so it has everything. Good luck coding. stackblitz.com/edit/angular-d5aypp

– kvetis
Mar 22 at 15:30






I got that working. I expanded my answer so it has everything. Good luck coding. stackblitz.com/edit/angular-d5aypp

– kvetis
Mar 22 at 15:30




















draft saved

draft discarded
















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55301479%2fwhy-am-i-not-getting-any-data-ngrx%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

Swift 4 - func physicsWorld not invoked on collision? The Next CEO of Stack OverflowHow to call Objective-C code from Swift#ifdef replacement in the Swift language@selector() in Swift?#pragma mark in Swift?Swift for loop: for index, element in array?dispatch_after - GCD in Swift?Swift Beta performance: sorting arraysSplit a String into an array in Swift?The use of Swift 3 @objc inference in Swift 4 mode is deprecated?How to optimize UITableViewCell, because my UITableView lags

Access current req object everywhere in Node.js ExpressWhy are global variables considered bad practice? (node.js)Using req & res across functionsHow do I get the path to the current script with Node.js?What is Node.js' Connect, Express and “middleware”?Node.js w/ express error handling in callbackHow to access the GET parameters after “?” in Express?Modify Node.js req object parametersAccess “app” variable inside of ExpressJS/ConnectJS middleware?Node.js Express app - request objectAngular Http Module considered middleware?Session variables in ExpressJSAdd properties to the req object in expressjs with Typescript