I have a main component X
with two sub-components Y
and Z
. I am experimenting with signals in Angular 17. My query is how can I pass the value of a signal from sub-component Y
to sub-component Z
?
I have attempted the following approach which works initially, but fails to update when the signal's value changes.
subComponentY.component.ts
export const data = signal<any>('');
fetchData() {
this.loading = true;
const functions = getFunctions(getApp());
connectFunctionsEmulator(functions, 'localhost', 5001);
const getInfo = httpsCallable(functions, 'getInformation')
getInfo(this.url.value)
.then( (result: any) => {
// result.data returns an object
data.set(result.data);
console.log(data());
})
}
subComponentZ.component.ts
import { data } from '../subComponentY/subComponentY.component';
data_ = data;
subComponentZ.component.html
<p class="">{{data_().data.title}}</p>
Although the console displays the updated signal data, the HTML template does not reflect these changes. Any suggestions?