0
I am new to developing projects with Angular. I need, please, a great help.
I would like a class css
was changed in a <div></div>
inserted into the parent component and when a button was clicked on the child component the classes "sucess" and "Danger" alternate (toggle).
Below is an example:
Father.component.html
<app-child></app-child>
<div [ngClass]="status ? 'success' : 'danger'"></div>
Father.component.ts
import { Component, OnInit } from '@angular/core';
@Component({
selector: 'app-father',
templateUrl: './father.component.html',
styleUrls: ['./father.component.scss'],
})
export class FatherComponent implements OnInit {
status: boolean = false;
constructor() { }
ngOnInit(): void {
}
}
Child.component.html
<button (click)="clickEvent()">Mudar classe css no componente pai</button>
Child.component.ts
import { Component, OnInit} from '@angular/core';
@Component({
selector: 'app-child',
templateUrl: './child.component.html',
styleUrls: ['./child.component.scss']
})
export class ChildComponent implements OnInit {
status: boolean = false;
clickEvent(){
this.status = !this.status;
}
constructor() { }
ngOnInit(): void {
}
}
@Input() passes values from the parent component to child components, whereas the opposite is to pass values from the child component to the parent vc uses @Output() along with Eventemiter(), This is basic in Angular.
– LeAndrade
Yes this concept I know and I know it is basic, I was having trouble with the syntax for not having experience with the angular, but I already solved, I’ve made it work correctly.
– Munir Baarini
Yeah, yeah, yeah man.
– LeAndrade