2016-06-23 09:47:54 -07:00
|
|
|
/**
|
|
|
|
* @license
|
|
|
|
* Copyright Google Inc. All Rights Reserved.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by an MIT-style license that can be
|
|
|
|
* found in the LICENSE file at https://angular.io/license
|
|
|
|
*/
|
|
|
|
|
2016-08-30 18:07:40 -07:00
|
|
|
import {LifecycleHooks, reflector} from './private_import_core';
|
2016-04-28 17:50:03 -07:00
|
|
|
|
2015-08-31 18:32:32 -07:00
|
|
|
|
2016-06-28 11:35:59 -07:00
|
|
|
export function hasLifecycleHook(hook: LifecycleHooks, token: any): boolean {
|
2016-10-12 10:05:32 -07:00
|
|
|
return reflector.hasLifecycleHook(token, getHookName(hook));
|
2016-10-11 18:42:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
function getHookName(hook: LifecycleHooks): string {
|
|
|
|
switch (hook) {
|
|
|
|
case LifecycleHooks.OnInit:
|
|
|
|
return 'ngOnInit';
|
|
|
|
case LifecycleHooks.OnDestroy:
|
|
|
|
return 'ngOnDestroy';
|
|
|
|
case LifecycleHooks.DoCheck:
|
|
|
|
return 'ngDoCheck';
|
|
|
|
case LifecycleHooks.OnChanges:
|
|
|
|
return 'ngOnChanges';
|
|
|
|
case LifecycleHooks.AfterContentInit:
|
|
|
|
return 'ngAfterContentInit';
|
|
|
|
case LifecycleHooks.AfterContentChecked:
|
|
|
|
return 'ngAfterContentChecked';
|
|
|
|
case LifecycleHooks.AfterViewInit:
|
|
|
|
return 'ngAfterViewInit';
|
|
|
|
case LifecycleHooks.AfterViewChecked:
|
|
|
|
return 'ngAfterViewChecked';
|
|
|
|
}
|
2016-10-12 10:05:32 -07:00
|
|
|
}
|