import { Component , OnInit , Input , OnChanges , Output , EventEmitter } from '@angular/core' ; import { ActivatedRoute , Router } from "@angular/router" ; import { Group } from "../../models/group.model" ; import { ContextService } from "../../services/context.service" ; import { GroupService } from "../../services/groups/group.service" ; @ Component ( { selector : 'app-create-group-modal' , templateUrl : './create-group-modal.component.html' , styleUrls : [ './create-group-modal.component.scss' ] } ) export class CreateGroupModalComponent { constructor ( private router , private groupService , private context , private route ) { } private user = this . context . getUser ( ) ; public groupName = '' ; private _show ; @ Output ( ) showChange = new EventEmitter ( ) ; @ Output ( ) onCreate = new EventEmitter ( ) ; @ Input ( ) set show ( value ) { this . _show = value ; this . showChange . emit ( this . _show ) ; } get show ( ) { return this . _show ; } onCreateInner ( $event ) { this . groupService . createNewGroup ( this . groupName ) . then ( ( response ) => { let group = new Group ( this . groupName , [ this . user . id ] , [ ] ) ; group . id = response . id ; this . context . getAllGroups ( ) . push ( group ) ; this . onCreate . emit ( group ) ; this . close ( ) ; } ) ; } close ( ) { this . show = false ; } }