Не могу разобраться, как передать данные при помощи метода сервиса в initial state в Redux.
У меня есть
service, который работает с данными Products:
import { Injectable } from '@angular/core';
import { BehaviorSubject } from 'rxjs/BehaviorSubject';
import { Http, HttpModule, Response } from '@angular/http';
import { Observable } from 'rxjs/Rx';
import 'rxjs/add/operator/map';
@Injectable()
export class ProductsService {
private products = new BehaviorSubject<any>([]);
product = this.products.asObservable();
dataUrl = "./assets/products.json";
constructor( private _http: Http ) { }
getProducts(): Observable<any>{
return this._http.get(this.dataUrl)
.map((res: Response) => res.json());
}
updateProducts(product){
this.products.next(product);
}
}
И такой
store:
import { IProduct } from './product';
import { ADD_PRODUCT, REMOVE_PRODUCT, REMOVE_ALL_PRODUCTS } from './actions';
import { ProductsService } from './service/products.service';
export class IAppState {
products: IProduct[];
}
export const INITIAL_STATE: IAppState = {
constructror(private _prods: ProductsService){ }
products = this._prods.getProducts()
}
export function rootReducer(state, action){
switch(action.type){
case ADD_PRODUCT:
action.product.id = state.products.length + 1;
action.product.isAdded = true;
console.log(state.products)
return Object.assign({}, state, {
products: state.products.concat(Object.assign({}, action.product))
})
case REMOVE_PRODUCT:
action.product.isAdded = false;
return Object.assign({}, state, {
products: state.products.filter(p => p.id !== action.id)
})
case REMOVE_ALL_PRODUCTS:
return Object.assign({}, state, {
products:[]
})
}
return state;
}
Compiler ругается на строчку
constructror(private _prods: ProductsService){ }
. Пишет Unexpected token.
Каким образом всё же можно передать данные из service в initial state?