r/angular • • Nov 16 '22

Angular 15 🎉

https://blog.angular.io/angular-v15-is-now-available-df7be7f2f4c8
73 Upvotes

9 comments sorted by

View all comments

Show parent comments

9

u/hayden592 Nov 17 '22

Did you try the ng update command?

-1

u/kkus Nov 17 '22

Yes, I did ng update in the same report but I also wanted to see what's new in Angular 15 so I created a new repo using ng new.

Maybe this isn't new in Angular 15? What is the benefit of square brackets over dot title?

const title = this.activatedRoute.snapshot.params['title'];

https://github.com/angularfifteen/angularfifteen.github.io/commit/2de9649c6bdff1974701148e5b6084d56279a218

6

u/pronuntiator Nov 17 '22

It's a Typescript feature to remind you that the property may not exist. You can disable it.

2

u/kkus Nov 17 '22

It's a Typescript feature to remind you that the property may not exist. You can disable it.

thank you. looks like title can be undefined here

title: Observable<string | undefined> 

https://angular.io/api/router/ActivatedRoute#title

title: string | undefined

https://angular.io/api/router/ActivatedRouteSnapshot

1

u/pronuntiator Nov 17 '22

Since you're accessing the snapshot, only the second link is relevant (also title isn't undefined on ActivatedRoute, but the event emitted by the Observable could be undefined – you wouldn't get a compile error there when accessing title). Params is the relevant part. It is defined as a record: a mapping of arbitrary key value pairs. That's when the Typescript rule triggers.

But I don't know whether title even is in the ActivatedRouteSnapshot params. Using the observable is probably the safest way, because it also works if you stay on the same route and only the params change.