我的收藏看起来像这样.
{
"_id" : ObjectId("572c4ed33c1b5f51215219a8"),
"name" : "This is an angular course, and integeration with php",
"description" : "After we connected we can query or update the database just how we would using the mongo API with the exception that we use a callback. The format for callbacks is always callback(error, value) where error is null if no exception has occured. The update methods save, remove, update and findAndModify also pass the lastErrorObject as the last argument to the callback …Run Code Online (Sandbox Code Playgroud) 我在从 observable 内部分配对类的全局变量的响应时遇到了一个奇怪的问题。所以我的程序逻辑如下:
从弹性搜索中获取最新的播放列表 ID(我使用类型定义文件中的弹性搜索)。这将返回一个 PromiseLike,我将一个 then 操作符连接到它。
在承诺解决方案中,我进行了另一个 http get 调用(即一个可观察的)
在 Observable 订阅中,我将来自服务器的响应分配给我的全局数组。
代码工作正常,我得到了应有的响应,但我无法将变量分配给全局变量。
这是我的代码:
import {Component, OnInit} from '@angular/core';
import {PlaylistService} from '../api/services'
@Component({
selector: 'app-playlists',
templateUrl: './playlists.component.html',
styleUrls: ['./playlists.component.css']
})
export class PlaylistsComponent implements OnInit {
public playlists: any[] = [];
constructor(private playlistService: PlaylistService) {
}
ngOnInit() {
let that = this;
this.playlistService.listIds().then((val) => { // <-- promise resolution
return this.playlistService.getByIds(val).toPromise(); // <-- http get call which i then convert to promise for simplicity
}).then((res) => …Run Code Online (Sandbox Code Playgroud)