错误TS1005:“:”预期的TypeScript Angular6

时间:2018-08-20 11:05:05

标签: angular typescript tslint

尝试构建Angular 6应用时出现错误提示。

  src / app / util / notification.service.ts(14,9)中的

ERROR:错误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
            });
   }

}

可能是什么问题?

3 个答案:

答案 0 :(得分:6)

您可能想要类似的东西:

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

答案 1 :(得分:2)

错误与 TypeScript 配置有关。

通过显式指定属性名称来创建对象

{ timeout: this.timeOut }

答案 2 :(得分:1)

问题与您不在使用键值对超时

尝试一下

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
        });
    }
相关问题