You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 6 Next »


Inputs as signals

----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

Introduction

Angular signals provide a reactive way to handle state in applications. This new approach offers better performance optimization and cleaner code.


Example

This example shows how to use them as inputs with the old version of the Input decorator.


Signals can be used as inputs using the classic Input decorator until they are passed out of the developer preview. down arrow 

@Component(...)
class Component {
@Input(

Unknown macro: { alias}

)
set value(value: unknown)

Unknown macro: { this.demo.set(value); }

demo = signal<unknown | undefined>(undefined);
}


After Angular team release inputs as signals we can easily refactor our code to down arrow 

@Component(...)
class Component {
    demo = input<unknown | undefined>(undefined);
}

and all HTML templates where a component is used can remain unchanged due to the alias.


Conclusion

This approach allows us to use inputs as signals earlier.

----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

  • No labels