ngrx/store select不存在

dar*_*rdo 3 rxjs ngrx angular

我正在尝试使用以下代码重新创建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());
  }

}
Run Code Online (Sandbox Code Playgroud)

此代码创建了两个编译时错误:

Property 'select' does not exist on type 'Observable<TodoState>'.
Property 'select' does not exist on type 'Observable<AppState>'.
Run Code Online (Sandbox Code Playgroud)

我在Observable导入上尝试了一些不同的变体,但这似乎并不重要,所以我只是采用了示例应用程序所具有的:

import {Observable} from 'rxjs/Observable';
Run Code Online (Sandbox Code Playgroud)

任何帮助将不胜感激!

men*_*nix 5

看起来你没有导入select和let,尝试添加以下导入:

import '@ngrx/core/add/operator/select';
import 'rxjs/add/operator/let'; 
Run Code Online (Sandbox Code Playgroud)