From e17fe90aaa7edba01fbcd886e6900276a6206cef Mon Sep 17 00:00:00 2001 From: Paul Gschwendtner Date: Tue, 5 May 2020 16:47:14 +0200 Subject: [PATCH] refactor: fix undecorated classes with angular features in repo (#36921) A few instances of undecorated classes with Angular features have been discovered in the framework repo. This commit fixes those. PR Close #36921 --- .../lifecycle-hooks/src/app/peek-a-boo.component.ts | 6 ++++-- .../forms/src/directives/abstract_form_group_directive.ts | 3 ++- packages/router/src/router.ts | 5 +++-- packages/router/src/router_scroller.ts | 3 ++- packages/upgrade/src/dynamic/src/upgrade_ng1_adapter.ts | 1 + packages/upgrade/static/src/upgrade_component.ts | 5 +++-- 6 files changed, 15 insertions(+), 8 deletions(-) diff --git a/aio/content/examples/lifecycle-hooks/src/app/peek-a-boo.component.ts b/aio/content/examples/lifecycle-hooks/src/app/peek-a-boo.component.ts index dcee428753..2539b7f763 100644 --- a/aio/content/examples/lifecycle-hooks/src/app/peek-a-boo.component.ts +++ b/aio/content/examples/lifecycle-hooks/src/app/peek-a-boo.component.ts @@ -3,6 +3,7 @@ import { AfterContentInit, AfterViewChecked, AfterViewInit, + Directive, DoCheck, OnChanges, OnDestroy, @@ -15,7 +16,8 @@ import { LoggerService } from './logger.service'; let nextId = 1; // #docregion ngOnInit -export class PeekABoo implements OnInit { +@Directive() +export class PeekABooDirective implements OnInit { constructor(private logger: LoggerService) { } // implement OnInit's `ngOnInit` method @@ -34,7 +36,7 @@ export class PeekABoo implements OnInit { }) // Don't HAVE to mention the Lifecycle Hook interfaces // unless we want typing and tool support. -export class PeekABooComponent extends PeekABoo implements +export class PeekABooComponent extends PeekABooDirective implements OnChanges, OnInit, DoCheck, AfterContentInit, AfterContentChecked, AfterViewInit, AfterViewChecked, diff --git a/packages/forms/src/directives/abstract_form_group_directive.ts b/packages/forms/src/directives/abstract_form_group_directive.ts index 6d7e5caddc..42a0a03b28 100644 --- a/packages/forms/src/directives/abstract_form_group_directive.ts +++ b/packages/forms/src/directives/abstract_form_group_directive.ts @@ -6,7 +6,7 @@ * found in the LICENSE file at https://angular.io/license */ -import {OnDestroy, OnInit} from '@angular/core'; +import {Directive, OnDestroy, OnInit} from '@angular/core'; import {FormGroup} from '../model'; @@ -23,6 +23,7 @@ import {AsyncValidatorFn, ValidatorFn} from './validators'; * * @publicApi */ +@Directive() export class AbstractFormGroupDirective extends ControlContainer implements OnInit, OnDestroy { /** * @description diff --git a/packages/router/src/router.ts b/packages/router/src/router.ts index 91602c7b06..9378f53378 100644 --- a/packages/router/src/router.ts +++ b/packages/router/src/router.ts @@ -7,8 +7,8 @@ */ import {Location} from '@angular/common'; -import {Compiler, Injector, isDevMode, NgModuleFactoryLoader, NgModuleRef, NgZone, Type, ɵConsole as Console} from '@angular/core'; -import {BehaviorSubject, defer, EMPTY, Observable, of, Subject, Subscription} from 'rxjs'; +import {Compiler, Injectable, Injector, isDevMode, NgModuleFactoryLoader, NgModuleRef, NgZone, Type, ɵConsole as Console} from '@angular/core'; +import {BehaviorSubject, EMPTY, Observable, of, Subject, Subscription} from 'rxjs'; import {catchError, filter, finalize, map, switchMap, tap} from 'rxjs/operators'; import {QueryParamsHandling, Route, Routes, standardizeConfig, validateConfig} from './config'; @@ -288,6 +288,7 @@ function defaultRouterHook(snapshot: RouterStateSnapshot, runExtras: { * * @publicApi */ +@Injectable() export class Router { private currentUrlTree: UrlTree; private rawUrlTree: UrlTree; diff --git a/packages/router/src/router_scroller.ts b/packages/router/src/router_scroller.ts index 99ce3adb5b..9e5864b0b9 100644 --- a/packages/router/src/router_scroller.ts +++ b/packages/router/src/router_scroller.ts @@ -7,12 +7,13 @@ */ import {ViewportScroller} from '@angular/common'; -import {OnDestroy} from '@angular/core'; +import {Injectable, OnDestroy} from '@angular/core'; import {Unsubscribable} from 'rxjs'; import {NavigationEnd, NavigationStart, Scroll} from './events'; import {Router} from './router'; +@Injectable() export class RouterScroller implements OnDestroy { // TODO(issue/24571): remove '!'. private routerEventsSubscription!: Unsubscribable; diff --git a/packages/upgrade/src/dynamic/src/upgrade_ng1_adapter.ts b/packages/upgrade/src/dynamic/src/upgrade_ng1_adapter.ts index 46cf4bec83..13402f54d7 100644 --- a/packages/upgrade/src/dynamic/src/upgrade_ng1_adapter.ts +++ b/packages/upgrade/src/dynamic/src/upgrade_ng1_adapter.ts @@ -135,6 +135,7 @@ export class UpgradeNg1ComponentAdapterBuilder { } } +@Directive() class UpgradeNg1ComponentAdapter implements OnInit, OnChanges, DoCheck { private controllerInstance: IControllerInstance|null = null; destinationObj: IBindingDestination|null = null; diff --git a/packages/upgrade/static/src/upgrade_component.ts b/packages/upgrade/static/src/upgrade_component.ts index 956b02dbf2..2002ddf5c5 100644 --- a/packages/upgrade/static/src/upgrade_component.ts +++ b/packages/upgrade/static/src/upgrade_component.ts @@ -6,9 +6,9 @@ * found in the LICENSE file at https://angular.io/license */ -import {DoCheck, ElementRef, EventEmitter, Injector, OnChanges, OnDestroy, OnInit, SimpleChanges, ɵlooseIdentical as looseIdentical} from '@angular/core'; +import {Directive, DoCheck, ElementRef, EventEmitter, Injector, OnChanges, OnDestroy, OnInit, SimpleChanges, ɵlooseIdentical as looseIdentical} from '@angular/core'; -import {IAttributes, IAugmentedJQuery, IDirective, IDirectivePrePost, IInjectorService, ILinkFn, IScope, ITranscludeFunction} from '../../src/common/src/angular1'; +import {IAttributes, IAugmentedJQuery, IDirective, IInjectorService, ILinkFn, IScope, ITranscludeFunction} from '../../src/common/src/angular1'; import {$SCOPE} from '../../src/common/src/constants'; import {IBindingDestination, IControllerInstance, UpgradeHelper} from '../../src/common/src/upgrade_helper'; import {isFunction} from '../../src/common/src/util'; @@ -66,6 +66,7 @@ class Bindings { * * @publicApi */ +@Directive() export class UpgradeComponent implements OnInit, OnChanges, DoCheck, OnDestroy { private helper: UpgradeHelper;