There is no such concept as Angular Signals. However, Angular has a powerful event system that is usually used for component interaction. You can use the @Output
decorator to define a custom event and signal other components when something happens. Here's an example:
index.ts341 chars16 lines
In the above example, the ChildComponent
has a custom event called messageEvent
defined using the @Output
decorator. It also has a method called sendMessage()
that emits the messageEvent
event with a payload.
Here is an example of how to subscribe to the event and handle it in ParentComponent
:
index.ts316 chars17 lines
In this example, ParentComponent
subscribes to the messageEvent
event of the ChildComponent
using (messageEvent)="receiveMessage($event)"
. It also has a method called receiveMessage($event: string)
that handles the event payload and updates the message
property. Finally, it passes the message
property to the template using interpolation {{ message }}
.
Hope this helps!
gistlibby LogSnag