Answer the question
In order to leave comments, you need to log in
How to pass variable value from one component to another component?
Hello everyone and I apologize for a completely stupid question, but I can’t figure out such a task:
There are two components, one Home and the other Second.
The Home component renders the page, and the Second component "does something there" and changes the boolean in the console to the opposite value:
import { Component, OnInit } from '@angular/core';
@Component({
selector: 'app-second',
templateUrl: './second.component.html',
styleUrls: ['./second.component.scss']
})
export class SecondComponent implements OnInit {
other: boolean
constructor() { }
ngOnInit(): void {
this.other=true
console.log(this.other)
//что-то делает и потом
this.other=false
console.log(this.other)
}
}
import { Component, OnInit } from '@angular/core';
@Component({
selector: 'app-home',
templateUrl: './home.component.html',
styleUrls: ['./home.component.scss']
})
export class HomeComponent implements OnInit {
myBool: boolean
constructor() { }
ngOnInit(): void {
this.myBool= this.other // беру из second компонента?!
console.log(this.myBool)
}
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question