我尝试使用以下代码重新创建ngrx / store示例项目,我知道这对于TODO应用程序来说有点过分,但是想要理解这些概念:
// 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>'.
我已经在Observable导入上尝试了一些不同的变体,但这似乎并不重要,所以我只是采用了示例应用程序的内容:
import {Observable} from 'rxjs/Observable';
非常感谢任何帮助!
答案 0 :(得分:5)
看起来您没有导入select并让我们尝试添加以下导入:
import '@ngrx/core/add/operator/select';
import 'rxjs/add/operator/let';