import { Component, OnInit, OnDestroy } from '@angular/core'; import { MainService } from './main.service'; @Component({ selector: 'my-main', templateUrl: './main.component.html', styleUrls: ['./main.component.less'] }) export class MainComponent implements OnInit, OnDestroy { title: string; constructor(private service: MainService) { this.title = this.service.title; this.service.missionTitle$.subscribe(title => { this.title = title; }); } toggleCollapsed() { this.service.menuMission(!this.service.isCollapsed); } ngOnInit() { } ngOnDestroy() { } }