2016-08-10 102 views
2

我想用下面的代碼重新創建ngrx/store示例項目,我知道這對TODO應用程序來說有點矯枉過正,但是想要理解概念:ngrx/store select does not exist

// State Model 
interface Todo { 
    id: number; 
    text: string; 
    completed: boolean; 
} 

interface TodoState { 
    entities: Todo[]; 
} 

interface AppState { 
    todos: TodoState; 
} 

// State Retrieval 
getTodos() { 
    return (state: Observable<TodoState>) => state.select(s => s.entities); 
} 

getTodoState() { 
    return (state: Observable<AppState>) => state.select(s => s.todos); 
} 

getTodosCollection() { 
    return compose(this.getTodos(), this.getTodoState()); 
} 

@Component({...}) 
class App { 
    // I'd think I should be able to type this to Array<Todo>, 
    // but that throws a compile-time error. 
    // Also, I'm assuming the $ is convention to designate 
    // a stream. 
    todos$: Observable<any>; 

    constructor(private store:Store<AppState>) { 
    this.todos = store.let(this.getTodosCollection()); 
    } 

} 

此代碼創建兩個編譯時錯誤:

Property 'select' does not exist on type 'Observable<TodoState>'. 
Property 'select' does not exist on type 'Observable<AppState>'. 

我已經嘗試了一堆可觀測進口不同的變化,但是這似乎並不重要,所以我剛剛拿了應用程序示例:

import {Observable} from 'rxjs/Observable'; 

任何幫助將不勝感激!

回答

5

它看起來像您沒有導入選擇讓,嘗試添加以下的進口:

import '@ngrx/core/add/operator/select'; 
import 'rxjs/add/operator/let'; 
+0

這做到了!謝謝您的幫助! – dardo

相關問題