Angular computed signals are not getting updated
Nadie ha tomado este issue todavía.
Evaluación
- Dificultad
- 4/5
- Tiempo estimado
- 3-5 días
- Aptitud para principiantes
- 25/100
- Tipo de issue
- Error
- Claridad
- Necesita aclaración
- Estado de actividad
- Estancado
- Stack tecnológico
- angular, typescript
Línea de trabajo
Comienza reproduciendo el ejemplo de señal computada usando _onSubMenuPage y _currentRoute, y luego compara las actualizaciones directas de señales con la solución alternativa toObservable. Investiga las actualizaciones de señales y el renderizado en diferentes PageRouterOutlets, incluida la necesidad de ChangeDetectorRef.detectChanges(). Se considera terminado cuando los valores computados se actualizan y los componentes se vuelven a renderizar sin detección de cambios manual.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
Environment
OS: macOS 14.1.2
CPU: (10) arm64 Apple M1 Pro
Shell: /bin/zsh
node: 18.17.1
npm: 9.6.7
nativescript: 8.6.1
# android
java: 11.0.21
ndk: Not Found
apis: Not Found
build_tools: Not Found
system_images: Not Found
# ios
xcode: 15.1/15C65
cocoapods: 1.14.3
python: 3.11.6
python3: 3.11.6
ruby: 2.7.8
platforms:
- DriverKit 23.2
- iOS 17.2
- macOS 14.2
- tvOS 17.2
- watchOS 10.2
Dependencies
"dependencies": {
"@angular/animations": "17.0.8",
"@angular/common": "17.0.8",
"@angular/compiler": "17.0.8",
"@angular/core": "17.0.8",
"@angular/forms": "17.0.8",
"@angular/platform-browser": "17.0.8",
"@angular/platform-browser-dynamic": "17.0.8",
"@angular/router": "17.0.8",
"@apollo/client": "3.8.8",
"@mnd/external-web-view": "file:../app-plugins/dist/packages/external-web-view/mnd-external-web-view-1.0.1.tgz",
"@nativescript/angular": "17.0.0",
"@nativescript/core": "8.6.2",
"@nativescript/iqkeyboardmanager": "2.1.1",
"@nativescript/localize": "5.2.0",
"@nativescript/mlkit-barcode-scanning": "file:../app-plugins-customized/mlkit/dist/packages/mlkit-barcode-scanning/nativescript-mlkit-barcode-scanning-2.0.0.tgz",
"@nativescript/mlkit-core": "file:../app-plugins-customized/mlkit/dist/packages/mlkit-core/nativescript-mlkit-core-2.0.0.tgz",
"@nativescript/secure-storage": "3.0.3",
"@nativescript/theme": "3.0.2",
"@nativescript/ui-charts": "0.2.4",
"apollo-angular": "6.0.0",
"apollo3-cache-persist": "0.14.1",
"d3-ease": "3.0.1",
"graphql": "16.8.1",
"graphql-tag": "2.12.6",
"intl": "1.2.5",
"moment": "2.29.4",
"nativescript-health-data": "file:../app-plugins-customized/nativescript-health-data/publish/package/nativescript-health-data-2.0.0.tgz",
"nativescript-oauth2-ext": "file:../app-plugins-customized/nativescript-oauth2-ext/publish/package/nativescript-oauth2-ext-3.0.3.tgz",
"nativescript-sqlite": "2.8.6",
"nativescript-sqlite-commercial": "file:../app-plugins-customized/commercial-sqlite/nativescript-sqlite-commercial-1.8.0.tgz",
"nativescript-sqlite-encrypted": "file:../app-plugins-customized/commercial-sqlite/nativescript-sqlite-encrypted-1.6.0.tgz",
"nativescript-ui-calendar": "15.2.3",
"nativescript-ui-gauge": "15.2.3",
"qs": "npm:querystring@0.2.1",
"rxjs": "7.8.1",
"util": "0.12.5",
"uuidjs": "5.0.1",
"zone.js": "0.14.2"
},
"devDependencies": {
"@angular-devkit/build-angular": "17.0.7",
"@angular/compiler-cli": "17.0.8",
"@graphql-codegen/cli": "5.0.0",
"@graphql-codegen/fragment-matcher": "5.0.0",
"@graphql-codegen/introspection": "4.0.0",
"@graphql-codegen/typescript": "4.0.1",
"@graphql-codegen/typescript-apollo-angular": "4.0.0",
"@graphql-codegen/typescript-operations": "4.0.1",
"@nativescript/android": "8.6.2",
"@nativescript/ios": "8.6.3",
"@nativescript/types": "8.6.1",
"@nativescript/webpack": "5.0.18",
"@ngtools/webpack": "17.0.7",
"@types/d3-ease": "3.0.2",
"@types/intl": "1.2.2",
"@types/lodash": "^4.14.202",
"@types/node": "20.10.5",
"keycloak-request-token": "0.1.0",
"rimraf": "5.0.5",
"sass": "1.69.5",
"ts-node": "10.9.2",
"typescript": "5.2.2"
}
Describe the bug
I am currently upgrading my app to use Angulars new signal api. WritableSignal is working as expected. However computed signals seem to be not working correctly. My computed signals are initialised correctly but are not update if the referenced WritableSignal is updated with .set() or .update(()=>{}) functions. If I convert the WritabelSignal with toObservable() (my current workaorund) things are working as expected.
I am also observing that WritableSignal changes to not always lead to rerendering of the component. When changing the WritableSignal Value in the observable subscription as shown below, I have to call ChangeDetectorRef.detectChanges() to update the ui.
To Reproduce
Here is an example computed signal:
public _onSubMenuPage = computed(() => this.navSrv._currentRoute().startsWith('/sub-menu('));
This references:
public _currentRoute = signal('');
which I tried to update with .set() and .update() methods
Expected behavior
I expected the computed signal to be updated when its value changes to a different value than the current one.
Sample project
Additional context
When I convert the WritableSignal to an observable and subscribe to it, I get notfied through changes. This can be considered as a workaround as long as the computed methods is not working.
this._currentRoute$ = toObservable(this.navSrv._currentRoute);
Update: The issue might be related to the fact that I am using the signals in components that reside in different PageRouterOutlets. I can use an effect(()=>void) to update component state but than have to call ChangeDetectorRef.detectChanges() in order for the changes to get rendered.
- Lenguaje dominante
- TypeScript
- Estrellas
- 55
- Forks
- 13
- Merge medio
- 16 min
- PR fusionados (30 d)
- 1
Guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de NativeScript/angular
-
Dificultad 4/5 3-5 días Aptitud para principiantes 45/100
NativeScript/angular#170 · 1 comentario ·
-
Dificultad 5/5 Más de una semana Aptitud para principiantes 35/100
NativeScript/angular#164 ·
-
My types are gone Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 45/100
NativeScript/angular#163 · 1 comentario ·
-
Dificultad 4/5 3-5 días Aptitud para principiantes 38/100
NativeScript/angular#158 · 1 reacción ·
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 35/100
NativeScript/angular#155 ·
Todos los issues de NativeScript/angular
Issues similares
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
0xMiden/bridge-portal#132 ·
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 82/100
-
area:tools bug good first issue help wanted priority:P2
Dificultad 2/5 1-3 horas Aptitud para principiantes 90/100
TaewoooPark/Motifcode#14 ·
-
bug
Dificultad 2/5 1-3 horas Aptitud para principiantes 84/100
newrelic-experimental/preflight#793 · 1 comentario ·