代码之家  ›  专栏  ›  技术社区  ›  Bishan

错误TS1005:“:”应为TypeScript Angular6

  •  3
  • Bishan  · 技术社区  · 7 年前

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

    有什么问题吗?

    3 回复  |  直到 7 年前
        1
  •  7
  •   Andrei Tătar    7 年前

    你可能想要这样的东西:

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

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

    this.toastr.error('<span class="now-ui-icons ui-1_bell-53"></span> ' + toast_msg, msg_title, this.timeOut);
    
        2
  •  3
  •   Suren Srapyan    7 年前

    类型脚本 配置。

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

    { timeout: this.timeOut }
    
        3
  •  1
  •   Aniket Avhad    7 年前

    您不使用键值对超时的问题

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