错误 TS1005:':' 应为 TypeScript Angular6

error TS1005: ':' expected TypeScript Angular6

我在尝试构建我的 Angular 6 应用程序时遇到以下错误。

ERROR in src/app/util/notification.service.ts(14,9): error TS1005: ':' expected.

这里是相关代码

import { Injectable } from '@angular/core';
import { ToastrService } from 'ngx-toastr';

@Injectable()
export class NotificationService {

    timeOut: number = 5000;

    constructor(private toastr: ToastrService) {}

    error(toast_msg, msg_title){

            this.toastr.error('<span class="now-ui-icons ui-1_bell-53"></span> ' + toast_msg, msg_title, {
                this.timeOut
            });
   }

}

可能是什么问题?

你可能想要这样的东西:

this.toastr.error('<span class="now-ui-icons ui-1_bell-53"></span> ' + toast_msg, msg_title, {
  timeout: this.timeOut,
});

或者,由于其余参数作为 args 传递:

this.toastr.error('<span class="now-ui-icons ui-1_bell-53"></span> ' + toast_msg, msg_title, this.timeOut);

错误与 TypeScript 配置有关。

通过显式提供 属性 名称来创建您的对象

{ timeout: this.timeOut }

你的问题是没有为超时使用键值对

试试这个,

error(toast_msg, msg_title) {
        this.toastr.error('<span class="now-ui-icons ui-1_bell-53"></span> ' + toast_msg, msg_title, {
            timeOut: this.timeOut
        });
    }