I am using redux with angular2 and trying to call windows azure search. I
wrote this code: types.ts
export interface IAppState {
languageState?: LanguageState;
searchState?: SearchState;
}
export type SearchState = si.Immutable<{
searchResult: SearchResult;
isLoading: boolean;
}>;
rootReducer:
export const rootReducer = combineReducers({
searchState: searchReducer
});
search.reducer:
const INITIAL_SEARCH_STATE: SearchState = si.from({
searchResult: new SearchResult(0, [], []),
isLoading: false
});
export function searchReducer( state: SearchState = INITIAL_SEARCH_STATE,
action: Action): SearchState {
switch (action.type) {
case SearchActions.SEARCH_RESULT_LOADING: {
return state.set('isLoading', true);
};
case SearchActions.SEARCH_RESULT_LOADED: {
return state.set('isLoading', false).set('searchResult',
action['payload']);
};
default:
return state;
}
}
search.actions:
@Injectable()
export class SearchActions {
static SEARCH_RESULT_LOADING = 'SEARCH_RESULT_LOADING';
static SEARCH_RESULT_LOADED = 'SEARCH_RESULT_LOADED';
constructor(private ngRedux: NgRedux<IAppState>, private searchService:
SearchService) { }
search(searchItem: SearchItem) {
const searchOptions = new SearchAzureOptions(searchItem);
this.ngRedux.dispatch({
type: SearchActions.SEARCH_RESULT_LOADING,
});
this.searchService.searchEntries(searchOptions.getSearchOptions()).subscribe(result
=> {
this.ngRedux.dispatch({
type: SearchActions.SEARCH_RESULT_LOADED,
payload: result
});
});
}
}
searchResult class:
export class SearchResult {
count: number;
products: Product[];
Facets: Facet[];
constructor(count: number, products: Product[], facets: Facet[]) {
this.count = count;
this.products = products;
this.Facets = facets;
}
}
search service:
searchEntries(searchOptions: any): Observable<SearchResult> {
return this.http
.post('link',
searchOptions, new RequestOptions({ headers: this.headers }))
.map(res => res.json())
.map(row => new SearchResult(row['count'] as number, row['value'] as
Product[], null))
.retry(5)
.catch((error: any) => this.searchHandleError(error));
}
and the component:
@select()
SearchState$: Observable<SearchState>;
constructor(private actions: SearchActions) {
this.actions.search(searchItem);
}
html:
{{ (SearchState$ | async) == null }}
everything is to be okay and I can see the result in the Redux extension in
the Chrome, which they are right. but I always get true as a result of my
HTML. the redux is right. the service is right but I cannot find the
problem.
any tip could be helpful. thank you.
P.S. the JSON Object names are right.
--
You received this message because you are subscribed to the Google Groups
"Angular and AngularJS discussion" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/angular.
For more options, visit https://groups.google.com/d/optout.