From df328361fdb3e0c0a937097c88a18831af52159b Mon Sep 17 00:00:00 2001 From: Adam Bradley Date: Thu, 28 Apr 2016 11:29:48 -0500 Subject: [PATCH] chore(id): finding component by an id attr has been removed BREAKING CHANGES: app.getComponent() has been removed. Please use Angular's ViewChild annotation instead: http://learnangular2.com/viewChild/ --- ionic/components.ts | 1 - ionic/components/app/app.ts | 54 +++------------------- ionic/components/app/id.ts | 89 ------------------------------------- ionic/config/directives.ts | 2 - 4 files changed, 7 insertions(+), 139 deletions(-) delete mode 100644 ionic/components/app/id.ts diff --git a/ionic/components.ts b/ionic/components.ts index 0fd88975919..cb5185b5d35 100644 --- a/ionic/components.ts +++ b/ionic/components.ts @@ -1,5 +1,4 @@ export * from './components/app/app'; -export * from './components/app/id'; export * from './components/action-sheet/action-sheet'; export * from './components/alert/alert'; export * from './components/badge/badge'; diff --git a/ionic/components/app/app.ts b/ionic/components/app/app.ts index b5693d9a841..bcb9941894b 100644 --- a/ionic/components/app/app.ts +++ b/ionic/components/app/app.ts @@ -12,7 +12,6 @@ import {Platform} from '../../platform/platform'; */ @Injectable() export class IonicApp { - private _cmps: {[id: string]: any} = {}; private _disTime: number = 0; private _scrollTime: number = 0; private _title: string = ''; @@ -145,59 +144,20 @@ export class IonicApp { /** * @private - * Register a known component with a key, for easy lookups later. - * @param {string} id The id to use to register the component - * @param {object} component The component to register - */ - register(id: string, component: any) { - this._cmps[id] = component; - } - - /** - * @private - * Unregister a known component with a key. - * @param {string} id The id to use to unregister - */ - unregister(id: string) { - delete this._cmps[id]; - } - - /** - * @private - * Get a registered component with the given type (returns the first) - * @param {object} cls the type to search for - * @return {object} the matching component, or undefined if none was found */ getRegisteredComponent(cls: any): any { - for (let key in this._cmps) { - const component = this._cmps[key]; - if (component instanceof cls) { - return component; - } - } + // deprecated warning: added 2016-04-28, beta7 + console.warn('Using app.getRegisteredComponent() to query components has been deprecated. ' + + 'Please use Angular\'s ViewChild annotation instead:\n\nhttp://learnangular2.com/viewChild/'); } /** - * Get the component for the given key. + * @private */ getComponent(id: string): any { - // deprecated warning - if (/menu/i.test(id)) { - console.warn('Using app.getComponent(menuId) to control menus has been deprecated as of alpha55.\n' + - 'Instead inject MenuController, for example:\n\n' + - 'constructor(menu: MenuController) {\n' + - ' this.menu = menu;\n' + - '}\n' + - 'toggleMenu() {\n' + - ' this.menu.toggle();\n' + - '}\n' + - 'openRightMenu() {\n' + - ' this.menu.open("right");\n' + - '}' - ); - } - - return this._cmps[id]; + // deprecated warning: added 2016-04-28, beta7 + console.warn('Using app.getComponent() to query components has been deprecated. ' + + 'Please use Angular\'s ViewChild annotation instead:\n\nhttp://learnangular2.com/viewChild/'); } /** diff --git a/ionic/components/app/id.ts b/ionic/components/app/id.ts deleted file mode 100644 index b070d4ac837..00000000000 --- a/ionic/components/app/id.ts +++ /dev/null @@ -1,89 +0,0 @@ -import {AppViewManager, ElementRef, Directive, Renderer, Input} from 'angular2/core'; - -import {IonicApp} from './app'; - -/** - * @private - * @name Id - * @description - * The `id` attribute is an easy way to identify unique components in an app and access them - * no matter where in the UI hierarchy you are. For example, this makes toggling - * a global side menu possible from any place in the application. - * - * @usage - * To give any component an ID, simply set its `id` property: - * ```html - * - * ``` - * - * To get a reference to the registered component, inject the [IonicApp](../IonicApp/) - * service: - * ```ts - * constructor(app: IonicApp) { - * this.app = app - * } - * - * ngAfterViewInit() { - * var checkbox = this.app.getComponent("myCheckbox"); - * if (checkbox.checked) { - * console.log('checkbox is checked'); - * } - * } - * ``` - * - * *NOTE:* It is not recommended to use ID's across Pages, as there is often no - * guarantee that the registered component has not been destroyed if its Page - * has been navigated away from. - * - * @demo /docs/v2/demos/id/ - */ -@Directive({ - selector: '[id]' -}) -export class IdRef { - private _component: any; - - /** - * @private - */ - @Input() id: string; - - constructor(private _app: IonicApp, elementRef: ElementRef, appViewManager: AppViewManager) { - // Grab the component this directive is attached to - this._component = appViewManager.getComponent(elementRef); - } - - /** - * @private - */ - ngOnInit() { - this._app.register(this.id, this._component); - } - - /** - * @private - */ - ngOnDestroy() { - this._app.unregister(this.id); - } -} - - -/** - * @private - */ -@Directive({ - selector: '[attr]' -}) - -export class Attr { - @Input() attr: string; - constructor(private _renderer: Renderer, private _elementRef: ElementRef) {} - -/** - * @private - */ - ngOnInit() { - this._renderer.setElementAttribute(this._elementRef.nativeElement, this.attr, ''); - } -} diff --git a/ionic/config/directives.ts b/ionic/config/directives.ts index 67f5e6553ae..4ae7d5ff944 100644 --- a/ionic/config/directives.ts +++ b/ionic/config/directives.ts @@ -38,7 +38,6 @@ import {Nav} from '../components/nav/nav'; import {NavPush, NavPop} from '../components/nav/nav-push'; import {NavRouter} from '../components/nav/nav-router'; import {NavbarTemplate, Navbar} from '../components/navbar/navbar'; -import {IdRef} from '../components/app/id'; import {ShowWhen, HideWhen} from '../components/show-hide-when/show-hide-when'; /** @@ -211,7 +210,6 @@ export const IONIC_DIRECTIVES = [ NavPush, NavPop, NavRouter, - IdRef, ShowWhen, HideWhen