Hi i have two components, component1 and component2
. And i have a value, lets say x
, and i want to pass the value to one of my component in my app, both have no parent-child or any relationship each other. How can i get the value x in component2 which is been set or created in component1? I know i can use local storage to set the value and get anywhere. Other than that is there any other way to do this? Sorry am new to Angular. Any idea guys? Thanks in advance.
currently what i have done in my component1:
window.localStorage.setItem('myVal', JSON.stringify(x));
and in my component2:
let getmyVal: any = JSON.parse(localStorage.getItem("myVal"));
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…