import { Component, OnInit, Input } from '@angular/core'; import { MatCheckboxChange } from '@angular/material/checkbox'; import { UserService } from '../user.service'; @Component({ selector: 'app-service', templateUrl: './service.component.html', styleUrls: ['./service.component.css'] }) export class ServiceComponent implements OnInit { @Input() serviceData: any; constructor( public userService: UserService, ) { } ngOnInit() { } public getDeployment() { const deployment = this.userService.user.deployments.find( d => { return d.service.name === this.serviceData.name; } ); return deployment; } public isDeployed(key): boolean { const deployment = this.getDeployment(); if (deployment) { return deployment.ssh_keys.some(k => { return k.name === key.name; }); } return false; } public deploymentChange(key) { console.log('changing', key); if (!this.isDeployed(key)) { this.userService.addDeployment(this.serviceData.name, key.name); } else { this.userService.removeDeployment(this.serviceData.name, key.name); } } }