-2
我需要做一个红绿灯,从0至10分钟是绿色的,从10至20的黄色和从20到30的红色,时间是由服务角度:如何使时间信号
到目前为止,是我的代码
这是组件
import {
Component,
OnInit,
Input
} from '@angular/core';
import {
TiempoService
} from "app/servicios/tiempo.service"
@Component({
selector: 'app-menu',
templateUrl: './menu.component.html',
styleUrls: ['./menu.component.css']
})
export class MenuComponent implements OnInit {
@Input() tiemposervice: TiempoService;
constructor() {}
ngOnInit() {
}
}
这是HTML
<div class="row">
<div class="small-12 medium-6 columns">
<span>Tiempo transcurrido</span>
<h5>{{tiempoTranscurrido | date:'mm:ss'}}</h5>
</div>
</div>
这是服务
import {
Injectable
} from '@angular/core';
import Rx from 'Rx';
@Injectable()
export class TiempoService {
tiempoTranscurrido: number;
constructor() {}
ngOnInit() {
}
tiempoTotal() {
Rx.Observable.interval(1000).subscribe(segundos => {
this.tiempoTranscurrido = segundos * 1000;
})
}
}
我将非常感谢您的帮助。
如果一切正常,但我希望它变成红色结束,你能不能帮我?谢谢 –
在'LightService'的'map'后面加'.take(2)'。 – 2017-06-14 11:46:55