Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angular/32.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
Angular 错误TS2345:类型为';日期';不可分配给类型为';字符串| IScheduler';_Angular_Ngrx - Fatal编程技术网

Angular 错误TS2345:类型为';日期';不可分配给类型为';字符串| IScheduler';

Angular 错误TS2345:类型为';日期';不可分配给类型为';字符串| IScheduler';,angular,ngrx,Angular,Ngrx,这是我的密码: 从“@angular/core”导入{Component}; 从“rxjs/Subject”导入{Subject}; 从“rxjs/Observable”导入{Observable}; 导入“rxjs/add/observable/interval”; 导入“rxjs/add/observable/merge”; 导入“rxjs/add/operator/map”; 导入“rxjs/add/operator/startWith”; 导入“rxjs/add/operator/sc

这是我的密码:

从“@angular/core”导入{Component};
从“rxjs/Subject”导入{Subject};
从“rxjs/Observable”导入{Observable};
导入“rxjs/add/observable/interval”;
导入“rxjs/add/observable/merge”;
导入“rxjs/add/operator/map”;
导入“rxjs/add/operator/startWith”;
导入“rxjs/add/operator/scan”;
导入“rxjs/add/operator/mapTo”;
@组成部分({
选择器:'应用程序根',
模板:`
更新
{{时钟|异步|日期:'yyyy-MM-dd HH:MM:ss'}
`
})
导出类AppComponent{
单击$=新建主题();
时钟;
构造函数(){
this.clock=Observable.merge(
点击$.mapTo('hour'),
可观测。间隔(1000)。映射到('秒')
)
.startWith(新日期())
.扫描((附件:日期,当前)=>{
const date:date=新日期(根据getTime());
如果(当前=='hour'){
date.setHours(date.getHours()+1);
}
如果(当前==‘秒’){
date.setSeconds(date.getSeconds()+1);
}
返回日期;
});
}

}
可观察。合并
将多个可观察转化为单个可观察。当您使用以下代码时,返回类型为
Observable

但是当您使用下面的代码段时,返回类型是
可观察的
,因此
扫描
操作符接受字符串作为第一个参数并给出错误

this.clock = Observable.merge(
      this.click$.mapTo('hour'),
      Observable.interval(1000).mapTo('second')
    )

您是否正在寻找具有的
开始,而不是具有
开始?
this.clock = Observable.merge(
      this.click$.mapTo('hour'),
      Observable.interval(1000).mapTo('second')
    )