投稿時間:2023-07-23 01:09:12 RSSフィード2023-07-23 01:00 分まとめ(11件)

カテゴリー等 サイト名等 記事タイトル・トレンドワード等 リンクURL 頻出ワード・要約等/検索ボリューム 登録日
python Pythonタグが付けられた新着投稿 - Qiita python と JupyterLab でボルケーノ https://qiita.com/kimisyo/items/392bf1a8b8eec6826ea8 jupyterlab 2023-07-23 00:18:56
python Pythonタグが付けられた新着投稿 - Qiita venv環境内でpipがFatal errorで動かなくなったときの対処法 https://qiita.com/niwatiki/items/935dd79c27ccc4bcd8d4 processusingcworkexa 2023-07-23 00:12:44
AWS AWSタグが付けられた新着投稿 - Qiita DataZone(プレビュー)に既存のGlueデータカタログを取り込みパブリッシュ/サブスクライブする https://qiita.com/yust0724/items/8381b16f530bc6fa8afd datazone 2023-07-23 00:30:31
海外TECH DEV Community Safe Route Param Injection in Angular with a Decorator https://dev.to/bwca/safe-route-param-injection-in-angular-with-a-decorator-1lk7 Safe Route Param Injection in Angular with a DecoratorThe intro and last passage of this article were provided by ChatGPT who was the first one to read the article and provide feedback The final code for this article is available at github since code fragments here are screenshots Route changes can have serious consequences in large Angular applications and sometimes cause ripple effects and hidden bugs When working with route parameters it s crucial to ensure safety and maintainability in the codebase In this article we will delve into a powerful technique that leverages TypeScript s type checking capabilities and a custom decorator to enhance the safety of extracting route parameters in Angular Traditionally developers have relied on loosely defined strings for route parameters which can lead to potential bugs and errors In this article we ll address this concern by introducing a more robust approach We ll explore how TypeScript s static typing can be utilized to extract parameters accurately and enable intelligent code completion To further elevate safety we ll implement a custom decorator that leverages the power of observables This decorator will seamlessly inject route parameters into properties ensuring a clean and type safe approach throughout our Angular components By the end of this article you ll have a deep understanding of this technique and be equipped with the knowledge to implement safe route param injection in your Angular projects Let s embark on this journey to enhance safety and maintainability in our Angular applications Checking the classic Angular hall of heroes tutorial one can observe a code fragment dealing with getting hero id from route params in hero details component which reads as follows With the app routing module ts providing the following information about routes What are the points which can be improved here The first one is of course loose strings in paths there is no explicit connection between the id in the path to the details component and the id grabbed from the params in the component Should it become heroId something migh break silently Let us discover how typescript can be used to increase the safety of extracting params from route so only the existing params can be extracted and also how a decorator can be used for this purpose Therefore what we are aiming at is having heroId as an Observable injected into the hero details component via decorator Since a decorator is a function it is a bit tricky to have it access Router or ActivatedRoute however it is possible if APP INITIALIZER were to be used to pass those references to our decorator this could do the trick However there is a problem with this approach as property decorators would fire prior to APP INITIALIZER which means we need the references before we can get them To counter this we need something that can be available right away for subscription and which would serve as a channel to pass url params so we need a BehaviorSubject which will be used to broadcast params from the Router which is to be injected later with APP INITIALIZER Consider the following code fragment Now we have a broadcasting channel which we can use inside a function even before it starts receiving any events from the Router we would just need to keep our decorator function in this file so it has the access to it The time has come for some typescript kung fu w are going to write a generic to extract parameters from a string we know that paths cannot start with a forward slash and parameters are preceded by a column therefore a generic to extract them would look as follows Works like a charm now we have intellisense on our side The next thing would be swapping loose strings for consonants and using those in paths instead What is left now is to write a simple decorator function to do the param injections into a property which it will receive from the params BehaviorSubject created earlier Viola now we have a safe decorator for parameter injections which can be used in the hero details component as following Simple isn t it With this newfound knowledge you are now empowered to take your Angular applications to new heights of safety and maintainability Happy coding 2023-07-22 15:32:52
海外TECH CodeProject Latest Articles Wexflow - Open Source .NET Workflow Engine https://www.codeproject.com/Articles/5346143/Wexflow-Open-Source-NET-Workflow-Engine automation 2023-07-22 15:09:00
ニュース BBC News - Home Greece fires: Thousands flee homes and hotels on Rhodes as fires spread https://www.bbc.co.uk/news/world-europe-66279520?at_medium=RSS&at_campaign=KARANGA chief 2023-07-22 15:49:24
ニュース BBC News - Home Strictly's Amy reveals her second cancer diagnosis https://www.bbc.co.uk/news/articles/cd1e7j8kqllo?at_medium=RSS&at_campaign=KARANGA dowden 2023-07-22 15:13:31
ニュース BBC News - Home Hungarian Grand Prix: Lewis Hamilton beats Max Verstappen to take his first pole since 2021 https://www.bbc.co.uk/sport/formula1/66278958?at_medium=RSS&at_campaign=KARANGA Hungarian Grand Prix Lewis Hamilton beats Max Verstappen to take his first pole since Lewis Hamilton beats Max Verstappen in Hungarian Grand Prix qualifying to take his first pole position since the penultimate race of the season 2023-07-22 15:37:57
ニュース BBC News - Home Tour de France 2023: Tadej Pogacar salvages pride by winning stage 20 https://www.bbc.co.uk/sport/cycling/66278990?at_medium=RSS&at_campaign=KARANGA france 2023-07-22 15:41:33
IT 週刊アスキー ADATAのケースファン「XPG VENTO 120」シリーズにホワイトが追加 https://weekly.ascii.jp/elem/000/004/146/4146394/ adata 2023-07-23 00:27:00
IT 週刊アスキー 長さ169.9mmとコンパクトなGeForce RTX 4060が登場 https://weekly.ascii.jp/elem/000/004/146/4146393/ gainward 2023-07-23 00:11:00

コメント

このブログの人気の投稿

投稿時間:2021-06-17 05:05:34 RSSフィード2021-06-17 05:00 分まとめ(1274件)

投稿時間:2021-06-20 02:06:12 RSSフィード2021-06-20 02:00 分まとめ(3871件)

投稿時間:2020-12-01 09:41:49 RSSフィード2020-12-01 09:00 分まとめ(69件)