Angular NGRX从API获取信息
我正在尝试将执行OMDB搜索时来自API的信息输入,并将其放在Angular 13中的NGRX范围中。
下面是我试图插入范围的代码,但它指责错误 “类型'电影'丢失了类型'可观察的< movie []>'的属性:源,操作员,提升,订阅等。”
export class MovieSearchComponent implements OnInit {
movies$: Observable<Movie[]>;
Title = new FormControl;
constructor(private movieService: MovieService, private store: Store<MovieState>) {
this.movies$ = this.store.pipe(select(selectMovies));
}
ngOnInit(): void {
}
getMovie(): void {
this.movieService.getMovie(this.Title.value).subscribe(
movie => {
this.movies$ = movie
}
)
}
}
I'm trying to put the information that comes from the api when doing an omdb search and put it in the scope of NgRx in angular 13.
below is the code of which I am trying to insert the scope but it accuses the error
"Type 'Movie' is missing the following properties from type 'Observable<Movie[]>': source, operator, lift, subscribe, and 3 more."
export class MovieSearchComponent implements OnInit {
movies$: Observable<Movie[]>;
Title = new FormControl;
constructor(private movieService: MovieService, private store: Store<MovieState>) {
this.movies$ = this.store.pipe(select(selectMovies));
}
ngOnInit(): void {
}
getMovie(): void {
this.movieService.getMovie(this.Title.value).subscribe(
movie => {
this.movies$ = movie
}
)
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这个问题应该在此行中
。
在您的观察者功能中,您正在尝试分配“电影”值,即电影类型,因此它们不兼容。
要解决此问题,只需声明电影属性广告在观察者中使用它,而不是电影$ $
The issue should be in this line
the type of this.movies$ is Observable<Movie[]>, an observable that emits an array of Movie values.
In your observer function, your are trying to assign the "movie" value, that is of Movie type, so they are incompatible.
To solve this issue, just declare the movie property ad use it in your observer, instead of movies$
您需要更改以下代码
,并且必须从服务文件返回电影阵列。
You need to change the below code
and you must return Movie array from your service file.