<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Jhon Hernandez</title>
    <description>The latest articles on DEV Community by Jhon Hernandez (@jhonhernandez300).</description>
    <link>https://dev.to/jhonhernandez300</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F1617459%2Fd08a07f2-731e-45c2-bc5b-53e0d2a2194e.jpg</url>
      <title>DEV Community: Jhon Hernandez</title>
      <link>https://dev.to/jhonhernandez300</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/jhonhernandez300"/>
    <language>en</language>
    <item>
      <title>Parent component is not being refresed</title>
      <dc:creator>Jhon Hernandez</dc:creator>
      <pubDate>Fri, 16 Aug 2024 00:03:16 +0000</pubDate>
      <link>https://dev.to/jhonhernandez300/parent-component-is-not-being-refresed-28nb</link>
      <guid>https://dev.to/jhonhernandez300/parent-component-is-not-being-refresed-28nb</guid>
      <description>&lt;p&gt;I have a component that has 3 child components:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;!-- users-edit.component.html --&amp;gt;
&amp;lt;div class="full-width" *ngIf="!editMode"&amp;gt;
  &amp;lt;app-users-get-data
   (usersFetched)="onUsersFetched($event)"
   (submitPressed)="handleSubmitPressed($event)"
  &amp;gt;
  &amp;lt;/app-users-get-data&amp;gt;
&amp;lt;/div&amp;gt;

&amp;lt;div class="full-width" id="table" *ngIf="!editMode"&amp;gt;
  &amp;lt;app-users-show-table 
    [users]="users" 
    [submitted]="submitted"    
  &amp;gt; 
  &amp;lt;/app-users-show-table&amp;gt;
&amp;lt;/div&amp;gt;

&amp;lt;div class="full-width" *ngIf="editMode"&amp;gt;  
  &amp;lt;app-users-edit-action&amp;gt;&amp;lt;/app-users-edit-action&amp;gt;
&amp;lt;/div&amp;gt;

import { Component, OnInit, ChangeDetectorRef } from '@angular/core';
import { FormBuilder, FormGroup, Validators } from '@angular/forms';
import { iUserDTO } from '../../../models/iUserDTO';
import { EditCommunicationService } from '../../../services/user/edit-communication.service';
import { Router } from '@angular/router';

@Component({
  selector: 'app-users-edit',
  templateUrl: './users-edit.component.html',
  styleUrl: './users-edit.component.css'
})
export class UsersEditComponent implements OnInit {  
  users: iUserDTO[] | null = null;
  submitted: boolean = false;     
  editMode: boolean = false;

  constructor(
    private editCommunicationService: EditCommunicationService,
    private cdr: ChangeDetectorRef 
  )
  { 
  }

  ngOnInit() {
    console.log('ngOnInit of users-edit');    

    this.editCommunicationService.editModeChanged.subscribe((editMode: boolean) =&amp;gt; {
      console.log('editMode ', editMode);
      this.editMode = editMode;
      this.cdr.detectChanges(); 
    });
  }  

  onUsersFetched(users: iUserDTO[] | null) {
    this.users = users;
  }

  handleSubmitPressed(submitted: boolean) {    
    this.submitted = submitted;
  }  
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The first component gets the data, the second shows the results and the third one has a form to update an user. The second component has an EDIT button:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;button class="btn btn-success btn-sm" (click)="onEditUser(user)"&amp;gt;{{ 'EDIT' | translate }}&amp;lt;/button&amp;gt;

// users-show-table.component.ts
import { Component, Input, OnChanges, OnInit, SimpleChanges, Output, EventEmitter, ElementRef, ViewChild } from '@angular/core';
import { iUserDTO } from '../../../models/iUserDTO';
import { LocalStorageService } from '../../../helpers/local-storage.service';
import { UserService } from '../../../services/user/user.service';
import { TranslateService } from '@ngx-translate/core';
import { LanguageChangeService } from '../../../services/language-change-service';
import * as bootstrap from 'bootstrap';
import { EditCommunicationService } from '../../../services/user/edit-communication.service';

@Component({
  selector: 'app-users-show-table',
  templateUrl: './users-show-table.component.html',
  styleUrls: ['./users-show-table.component.css']
})
export class UsersShowTableComponent implements OnInit {
  action: string = '';
  responseMessage: string = '';
  messageStatus: string = '';
  messageHeader: string = '';
  modalMessage: string = '';
  modalHeader: string = '';
  modalVisible: boolean = false;
  private modal: bootstrap.Modal | null = null;
  serviceError: string = '';
  showServiceError: boolean = false;


  @ViewChild('errorModal') modalElementRef!: ElementRef;

  @Input() users: iUserDTO[] | null = null;
  @Input() submitted: boolean = false; 


  showDeleteAlert: boolean = false;
  userToDelete: iUserDTO | null = null;

  constructor(
    private localStorageService: LocalStorageService,
    private userService: UserService,
    private translate: TranslateService,
    private languageChangeService: LanguageChangeService,
    private editCommunicationService: EditCommunicationService
    ) 
    { 
      console.log('UsersShowTableComponent instanciado');
    }

  ngOnInit(): void {
    this.action = this.localStorageService.getData('action');
  }

  ngAfterViewInit() {
    this.modal = new bootstrap.Modal(this.modalElementRef.nativeElement);
  }  

  onEditUser(user: iUserDTO) {
    console.log('Editing user:', user);   
    this.editCommunicationService.notifyEditMode(true);    
  }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This is the service:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import { EventEmitter, Injectable } from '@angular/core';
import { BehaviorSubject } from 'rxjs';

@Injectable({
  providedIn: 'root'
})
export class EditCommunicationService {
  public editModeChanged: EventEmitter&amp;lt;boolean&amp;gt; = new EventEmitter&amp;lt;boolean&amp;gt;();

  constructor() {}

  notifyEditMode(editMode: boolean) {
    console.log('On the service ', editMode);
    this.editModeChanged.emit(editMode);
  }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;When the EDIT button is clicked, the parent componet should hide the first two components and the third one appear, but when I click the button, nothing happens.&lt;/p&gt;

&lt;p&gt;I put some console.log around, I can see the data on users-show and the service, not on users-edit.&lt;/p&gt;

</description>
      <category>angular</category>
    </item>
  </channel>
</rss>
