mirror of
https://github.com/angular/angular.git
synced 2026-09-14 13:54:52 +08:00
refactor(router): remove non-null assertions (#48244)
As part of #24571, removing non-null assertions (where appropriate) PR Close #48244
This commit is contained in:
committed by
Andrew Scott
parent
afc668acd5
commit
dac5860a47
@@ -19,10 +19,8 @@ export const ROUTER_SCROLLER = new InjectionToken<RouterScroller>('');
|
||||
|
||||
@Injectable()
|
||||
export class RouterScroller implements OnDestroy {
|
||||
// TODO(issue/24571): remove '!'.
|
||||
private routerEventsSubscription!: Unsubscribable;
|
||||
// TODO(issue/24571): remove '!'.
|
||||
private scrollEventsSubscription!: Unsubscribable;
|
||||
private routerEventsSubscription?: Unsubscribable;
|
||||
private scrollEventsSubscription?: Unsubscribable;
|
||||
|
||||
private lastId = 0;
|
||||
private lastSource: 'imperative'|'popstate'|'hashchange'|undefined = 'imperative';
|
||||
@@ -105,11 +103,7 @@ export class RouterScroller implements OnDestroy {
|
||||
|
||||
/** @nodoc */
|
||||
ngOnDestroy() {
|
||||
if (this.routerEventsSubscription) {
|
||||
this.routerEventsSubscription.unsubscribe();
|
||||
}
|
||||
if (this.scrollEventsSubscription) {
|
||||
this.scrollEventsSubscription.unsubscribe();
|
||||
}
|
||||
this.routerEventsSubscription?.unsubscribe();
|
||||
this.scrollEventsSubscription?.unsubscribe();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -115,9 +115,9 @@ export class ActivatedRoute {
|
||||
/** @internal */
|
||||
_routerState!: RouterState;
|
||||
/** @internal */
|
||||
_paramMap!: Observable<ParamMap>;
|
||||
_paramMap?: Observable<ParamMap>;
|
||||
/** @internal */
|
||||
_queryParamMap!: Observable<ParamMap>;
|
||||
_queryParamMap?: Observable<ParamMap>;
|
||||
|
||||
/** An Observable of the resolved route title */
|
||||
readonly title: Observable<string|undefined> =
|
||||
@@ -288,17 +288,13 @@ export class ActivatedRouteSnapshot {
|
||||
/** @internal */
|
||||
_resolve: ResolveData;
|
||||
/** @internal */
|
||||
// TODO(issue/24571): remove '!'.
|
||||
_resolvedData!: Data;
|
||||
_resolvedData?: Data;
|
||||
/** @internal */
|
||||
// TODO(issue/24571): remove '!'.
|
||||
_routerState!: RouterStateSnapshot;
|
||||
/** @internal */
|
||||
// TODO(issue/24571): remove '!'.
|
||||
_paramMap!: ParamMap;
|
||||
_paramMap?: ParamMap;
|
||||
/** @internal */
|
||||
// TODO(issue/24571): remove '!'.
|
||||
_queryParamMap!: ParamMap;
|
||||
_queryParamMap?: ParamMap;
|
||||
|
||||
/** The resolved route title */
|
||||
get title(): string|undefined {
|
||||
|
||||
@@ -189,8 +189,7 @@ function matrixParamsMatch(
|
||||
*/
|
||||
export class UrlTree {
|
||||
/** @internal */
|
||||
// TODO(issue/24571): remove '!'.
|
||||
_queryParamMap!: ParamMap;
|
||||
_queryParamMap?: ParamMap;
|
||||
|
||||
constructor(
|
||||
/** The root segment group of the URL tree */
|
||||
@@ -299,8 +298,7 @@ export class UrlSegmentGroup {
|
||||
*/
|
||||
export class UrlSegment {
|
||||
/** @internal */
|
||||
// TODO(issue/24571): remove '!'.
|
||||
_parameterMap!: ParamMap;
|
||||
_parameterMap?: ParamMap;
|
||||
|
||||
constructor(
|
||||
/** The path part of a URL segment */
|
||||
|
||||
@@ -123,18 +123,18 @@ describe('Integration', () => {
|
||||
`
|
||||
})
|
||||
class ComponentWithRouterLink {
|
||||
// TODO(issue/24571): remove '!'.
|
||||
@ViewChild(TemplateRef, {static: true}) templateRef!: TemplateRef<any>;
|
||||
// TODO(issue/24571): remove '!'.
|
||||
@ViewChild(TemplateRef, {static: true}) templateRef?: TemplateRef<any>;
|
||||
@ViewChild('container', {read: ViewContainerRef, static: true})
|
||||
container!: ViewContainerRef;
|
||||
container?: ViewContainerRef;
|
||||
|
||||
addLink() {
|
||||
this.container.createEmbeddedView(this.templateRef, {$implicit: '/simple'});
|
||||
if (this.templateRef) {
|
||||
this.container?.createEmbeddedView(this.templateRef, {$implicit: '/simple'});
|
||||
}
|
||||
}
|
||||
|
||||
removeLink() {
|
||||
this.container.clear();
|
||||
this.container?.clear();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user