首页 > 解决方案 > 错误 TS1005:“:”预期 TypeScript Angular6

问题描述

尝试构建我的 Angular 6 应用程序时出现以下错误。

src/app/util/notification.service.ts(14,9) 中的错误:错误 TS1005:预期为“:”。

这是相关代码

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
            });
   }

}

可能是什么问题?

标签: angulartypescripttslint

解决方案


你可能想要这样的东西:

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);

推荐阅读