From 898c66f6929e352992cbf59c156b106036d7ef05 Mon Sep 17 00:00:00 2001 From: cesar garay Date: Wed, 3 May 2017 10:20:36 -0300 Subject: [PATCH 1/2] Add output emiters --- .../+dropdown/demos/basic/basic-link.html | 4 ++-- .../+dropdown/demos/basic/basic-link.ts | 10 +++++++-- src/dropdown/bs-dropdown.directive.ts | 22 +++++++++++-------- 3 files changed, 23 insertions(+), 13 deletions(-) diff --git a/demo/src/app/components/+dropdown/demos/basic/basic-link.html b/demo/src/app/components/+dropdown/demos/basic/basic-link.html index 3388f78f9a..901d87434e 100644 --- a/demo/src/app/components/+dropdown/demos/basic/basic-link.html +++ b/demo/src/app/components/+dropdown/demos/basic/basic-link.html @@ -1,8 +1,8 @@ - + Click me for a dropdown, yo! - + \ No newline at end of file diff --git a/demo/src/app/components/+dropdown/demos/basic/basic-link.ts b/demo/src/app/components/+dropdown/demos/basic/basic-link.ts index 9564e1cf93..e66562e9d2 100644 --- a/demo/src/app/components/+dropdown/demos/basic/basic-link.ts +++ b/demo/src/app/components/+dropdown/demos/basic/basic-link.ts @@ -5,10 +5,16 @@ import { Component } from '@angular/core'; templateUrl: './basic-link.html' }) export class DemoDropdownBasicLinkComponent { - public items:string[] = ['The first choice!', + public items: string[] = ['The first choice!', 'And another choice for you.', 'but wait! A third!']; - public toggled(open:boolean):void { + public toggled(open: boolean): void { console.log('Dropdown is now: ', open); } + public onHidden(): void { + console.log('Dropdown is hide'); + } + public onShown(): void { + console.log('Dropdown is Show'); + } } diff --git a/src/dropdown/bs-dropdown.directive.ts b/src/dropdown/bs-dropdown.directive.ts index b07aeb427a..93c89c52f6 100644 --- a/src/dropdown/bs-dropdown.directive.ts +++ b/src/dropdown/bs-dropdown.directive.ts @@ -93,6 +93,7 @@ export class BsDropdownDirective implements OnInit, OnDestroy { * Emits an event when the popover is shown */ @Output() onShown: EventEmitter; + /** * Emits an event when the popover is hidden */ @@ -112,15 +113,15 @@ export class BsDropdownDirective implements OnInit, OnDestroy { private _isInited = false; constructor(private _elementRef: ElementRef, - private _renderer: Renderer, - private _viewContainerRef: ViewContainerRef, - private _cis: ComponentLoaderFactory, - private _config: BsDropdownConfig, - private _state: BsDropdownState) { + private _renderer: Renderer, + private _viewContainerRef: ViewContainerRef, + private _cis: ComponentLoaderFactory, + private _config: BsDropdownConfig, + private _state: BsDropdownState) { // create dropdown component loader this._dropdown = this._cis .createLoader(this._elementRef, this._viewContainerRef, this._renderer) - .provide({provide: BsDropdownState, useValue: this._state}); + .provide({ provide: BsDropdownState, useValue: this._state }); this.onShown = this._dropdown.onShown; this.onHidden = this._dropdown.onHidden; @@ -133,7 +134,7 @@ export class BsDropdownDirective implements OnInit, OnDestroy { // fix: seems there are an issue with `routerLinkActive` // which result in duplicated call ngOnInit without call to ngOnDestroy // read more: https://github.com/valor-software/ngx-bootstrap/issues/1885 - if (this._isInited) {return;} + if (this._isInited) { return; } this._isInited = true; this._showInline = !this.container; @@ -157,7 +158,7 @@ export class BsDropdownDirective implements OnInit, OnDestroy { // attach dropdown menu inside of dropdown if (this._showInline) { this._state.dropdownMenu - .then((dropdownMenu:BsComponentRef) => { + .then((dropdownMenu: BsComponentRef) => { this._inlinedMenu = dropdownMenu.viewContainer.createEmbeddedView(dropdownMenu.templateRef); }); } @@ -175,6 +176,7 @@ export class BsDropdownDirective implements OnInit, OnDestroy { if (this._showInline) { this._isInlineOpen = true; this._state.isOpenChange.emit(true); + this.onShown.emit(true); return; } @@ -191,13 +193,14 @@ export class BsDropdownDirective implements OnInit, OnDestroy { this._dropdown .attach(BsDropdownContainerComponent) .to(this.container) - .position({attachment: _placement}) + .position({ attachment: _placement }) .show({ content: dropdownMenu.templateRef, placement: _placement }); this._state.isOpenChange.emit(true); + this.onShown.emit(true); }); } @@ -217,6 +220,7 @@ export class BsDropdownDirective implements OnInit, OnDestroy { } this._state.isOpenChange.emit(false); + this.onHidden.emit(true); } /** From e53ebd74e140c18c3c95d6dd200010538d5d049a Mon Sep 17 00:00:00 2001 From: Ilya Surmay Date: Fri, 12 May 2017 15:36:49 +0300 Subject: [PATCH 2/2] fix(dropdown): remove unnecessary event binding and method --- .../app/components/+dropdown/demos/basic/basic-link.html | 4 ++-- .../src/app/components/+dropdown/demos/basic/basic-link.ts | 7 ++----- 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/demo/src/app/components/+dropdown/demos/basic/basic-link.html b/demo/src/app/components/+dropdown/demos/basic/basic-link.html index 901d87434e..a463d96ddf 100644 --- a/demo/src/app/components/+dropdown/demos/basic/basic-link.html +++ b/demo/src/app/components/+dropdown/demos/basic/basic-link.html @@ -1,8 +1,8 @@ - + Click me for a dropdown, yo! - \ No newline at end of file + diff --git a/demo/src/app/components/+dropdown/demos/basic/basic-link.ts b/demo/src/app/components/+dropdown/demos/basic/basic-link.ts index e66562e9d2..16c21cbb26 100644 --- a/demo/src/app/components/+dropdown/demos/basic/basic-link.ts +++ b/demo/src/app/components/+dropdown/demos/basic/basic-link.ts @@ -8,13 +8,10 @@ export class DemoDropdownBasicLinkComponent { public items: string[] = ['The first choice!', 'And another choice for you.', 'but wait! A third!']; - public toggled(open: boolean): void { - console.log('Dropdown is now: ', open); - } public onHidden(): void { - console.log('Dropdown is hide'); + console.log('Dropdown is hidden'); } public onShown(): void { - console.log('Dropdown is Show'); + console.log('Dropdown is shown'); } }