Angular6错误:未捕获(承诺):TypeError:(中间值).map不是函数

时间:2018-10-01 10:27:10

标签: typescript promise rxjs angular6 rxjs6

我今天更新了我的项目(从Angular5到Angular6),并且正在运行的代码开始出现错误........................... ................................................... .........................

error mesage

/**
 * Resolve
 * @param {ActivatedRouteSnapshot} route
 * @param {RouterStateSnapshot} state
 * @returns {Observable<any> | Promise<any> | any}
 */
resolve(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable<any> | Promise<any> | any {
    this.routeParams = route.params;
    return new Promise((resolve, reject) => {
        Promise.all([
            this.getCompany()
        ]).then(
            () => {
                if (this.routeParams.postKey) {
                    this.setCurrentMail(this.routeParams.postKey);
                }
                else {
                    this.setCurrentMail(null);
                }
                this.onSearchTextChanged.subscribe(searchText => {
                    if(searchText !== ''){
                        this.searchText = searchText;
                        this.getMailsByLabel();
                    }
                    else{
                    this.searchText = searchText;
                    this.getMailsByLabel();
                }
                });

                resolve();
            },
            reject
            );
    });
}

getCompany() {
    var companyIndex = this.routeParams.company;
    return new Promise((resolve, reject) => {
        this.db.list('corporateUsers/' + localStorage.getItem('currentUserId') + "/companies")
            .valueChanges().subscribe((company: any) => {
                if (company) {
                    resolve(company[companyIndex || 0])
                }
            },reject);
    }).then((company: any) => {
        this.company = company.uniqueName;
        return this.getMailsByLabel()
    });
}

我的package.json .......................................... .................................

"dependencies": {
"@agm/core": "1.0.0-beta.2",
"@angular/animations": "6.1.9",
"@angular/cdk": "6.4.7",
"@angular/common": "6.1.9",
"@angular/compiler": "6.1.9",
"@angular/core": "6.1.9",
"@angular/flex-layout": "6.0.0-beta.18",
"@angular/forms": "6.1.9",
"@angular/http": "6.1.9",
"@angular/material": "6.4.7",
"@angular/platform-browser": "6.1.9",
"@angular/platform-browser-dynamic": "6.1.9",
"@angular/router": "6.1.9",
"@ngu/carousel": "1.4.8",
"@ngx-translate/core": "10.0.2",
"@swimlane/ngx-charts": "7.4.0",
"@swimlane/ngx-datatable": "11.0.3",
"@withinpixels/ngx-dnd": "3.1.0",
"@xmlking/ngx-knob": "0.0.6",
"angular-calendar": "0.21.3",
"angular2-knob": "1.1.15",
"angularfire2": "5.0.0-rc.7",
"chart.js": "2.7.2",
"classlist.js": "1.1.20150312",
"core-js": "2.5.1",
"d3": "4.11.0",
"firebase": "5.0.1",
"hammerjs": "2.0.8",
"highlight.js": "9.12.0",
"intl": "1.2.5",
"moment": "2.19.2",
"ng2-imageupload": "1.4.2",
"ng2-img-cropper": "0.9.0",
"ngx-color-picker": "4.4.0",
"ngx-cookie-service": "1.0.9",
"ngx-moment": "2.0.0",
"perfect-scrollbar": "1.0.3",
"rxjs": "6.3.3",
"rxjs-compat": "6.3.3",
"web-animations-js": "2.3.1",
"zone.js": "^0.8.26"


"devDependencies": {
    "@angular-devkit/build-angular": "~0.8.0",
    "@angular/cli": "6.2.3",
    "@angular/compiler-cli": "6.1.9",
    "@angular/language-service": "6.1.9",
    "@angularclass/hmr": "2.1.3",
    "@types/jasmine": "2.5.54",
    "@types/jasminewd2": "2.0.3",
    "@types/node": "6.0.90",
    "codelyzer": "3.2.2",
    "jasmine-core": "2.6.4",
    "jasmine-spec-reporter": "4.1.1",
    "karma": "1.7.1",
    "karma-chrome-launcher": "2.1.1",
    "karma-cli": "1.0.1",
    "karma-coverage-istanbul-reporter": "1.3.0",
    "karma-jasmine": "1.1.0",
    "karma-jasmine-html-reporter": "0.2.2",
    "protractor": "5.1.2",
    "ts-node": "3.2.2",
    "tslint": "5.7.0",
    "typescript": "2.9.2"
  }

我在多个地方使用了地图功能。我添加了一个

 if (!this.routeParams["isAnswered"]) {
            this.mails = [];
             let path = this.routeParams["hashtag"] ? "hashtags/" + this.routeParams["hashtag"] + "/timeline" : "timeline";
            this.subscription = this.db.list("brand/" + this.company + "/" + path, ref => ref.orderByChild("order"))
                .snapshotChanges()
                .pipe(
                map(changes => {
                    return changes.filter(mail => mail.payload.val()['rating']['uniqueName'] === this.company && mail.payload.val()['repostedByUser'] === undefined).map(c => ({ $key: c.payload.key, ...c.payload.val() }));
                })
                )
                .subscribe((mails: any) => {

                    this.mails = mails.map(mail => {
                        return new Mail(mail);
                    });
                    this.mails = FuseUtils.filterArrayByString(this.mails, this.searchText);
                    this.onMailsChanged.next(this.mails);

                    resolve(this.mails);
                }, reject);

EDİT:

我更改了rxjs版本6.2.2并解决了问题,但是我不明白6.2.2到6.3.3做了什么更改?

0 个答案:

没有答案