General
: Bind route information to inputs
#10125
Labels
client
Pull requests that update TypeScript code. (Added Automatically!)
core
Pull requests that affect the corresponding module
exam
Pull requests that affect the corresponding module
exercise
Pull requests that affect the corresponding module
programming
Pull requests that affect the corresponding module
refactoring
text
Pull requests that affect the corresponding module
Refactoring
Context
Problem
Currently, if we wanted to use Route parameters (e.g.
courseId
andexerciseId
from/course-management/:courseId/programming-exercises/:exerciseId
) or Route data, we injectActivatedRoute
and subscribe to itsparams
ordata
Observable. The Subscription has to be unsubscribed when the component is destroyed. This approach is complex and boilerplate-heavy.Motivation
A simpler approach is to enable
withComponentInputBinding()
. Once enabled, input signals with a matching name can be used instead.This is approach is recommended Angular's Route Guide and available since Angular v16.
Example
ActivatedRoute
:withComponentInputBinding()
:Blocking Issues
To enable the feature,
withComponentInputBinding()
can be added to theprovideRouter()
call.However, we cannot enable it without breaking existing Components. Existing Component inputs without corresponding route data will be set to
undefined
. If the Component does not expectundefined
in its input, the Component will break.Docs:
Whilst Route Components cannot have required inputs (currently, inputs cannot be set via a route), the can have inputs with default values. These inputs will be set to
undefined
once the feature is enabled.Example
text-editor.route.ts:
text-editor.component.ts:
The RegEx
ActivatedRoute(.|\n)*?(input(<[^>]*>)\([^\)]+\)|@Input[^;]*=)
finds Components with defaulted inputs in files whereActivatedRoute
is imported. These Components are likely candidates for needing changes.However, other Components used in Routes might not import
ActvatedRoute
.Before the migration can be done, all affected Components need to be identified.
Components needing changes (incomplete)
The text was updated successfully, but these errors were encountered: