Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angular/33.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
错误TS1005:';:';预期的TypeScript Angular6_Angular_Typescript_Tslint - Fatal编程技术网

错误TS1005:';:';预期的TypeScript Angular6

错误TS1005:';:';预期的TypeScript Angular6,angular,typescript,tslint,Angular,Typescript,Tslint,我在尝试构建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: n

我在尝试构建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
            });
   }

}
从'@angular/core'导入{Injectable};
从“ngx-toastr”导入{ToastrService};
@可注射()
出口类通知服务{
超时:数字=5000;
构造函数(私有toastr:ToastrService){}
错误(toast\u msg,msg\u title){
此.toastr.error(“”+toast\u msg,msg\u title{
这是超时
});
}
}

可能是什么问题?

您可能想要以下内容:

this.toastr.error('<span class="now-ui-icons ui-1_bell-53"></span> ' + toast_msg, msg_title, {
  timeout: this.timeOut,
});
this.toastr.error(“”+toast\u msg,msg\u title{
timeout:this.timeout,
});
或者,由于其余参数作为参数传递:

this.toastr.error('<span class="now-ui-icons ui-1_bell-53"></span> ' + toast_msg, msg_title, this.timeOut);
this.toastr.error(“”+toast\u msg,msg\u title,this.timeOut);
错误与类型脚本配置有关

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

{ 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
        });
    }
错误(toast\u msg,msg\u title){
此.toastr.error(“”+toast\u msg,msg\u title{
超时:这是超时
});
}

@JoelHarkes
super()
用于扩展其他类的类。至于OP
{this.timeOut}
如果两个变量的名称不完全相同,则无法工作。和<代码>超时不同于<代码>。TimeOut< <代码>:考虑显式声明它。谢谢您的回答。我的错。应该是
timeout:this.timeout
谢谢你的回答。是的,我的代码中缺少属性名。这就是问题所在。