Skip to content

Commit

Permalink
fix(lib): nested viewMode templateRef on single click
Browse files Browse the repository at this point in the history
  • Loading branch information
geromegrignon committed Aug 17, 2020
1 parent bd19359 commit 07c8262
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 5 deletions.
6 changes: 2 additions & 4 deletions projects/ngneat/edit-in-place/src/lib/editable.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,9 @@ import {
OnInit,
Output,
TemplateRef,
ViewChild,
} from '@angular/core';
import { fromEvent, Observable, Subject, Subscription } from 'rxjs';
import { filter, switchMapTo, take, takeUntil } from 'rxjs/operators';
import { filter, skip, switchMapTo, take, takeUntil } from 'rxjs/operators';
import { ViewModeDirective } from './directives/view-mode.directive';
import { EditModeDirective } from './directives/edit-mode.directive';
import { EDITABLE_CONFIG, EditableConfig } from './editable.config';
Expand All @@ -33,8 +32,6 @@ export class EditableComponent implements OnInit, OnDestroy {
@ContentChild(ViewModeDirective) viewModeTpl: ViewModeDirective;
@ContentChild(EditModeDirective) editModeTpl: EditModeDirective;

@ViewChild('input') input: ElementRef;

private mode: Mode = 'view';
private readonly editMode: Subject<boolean> = new Subject<boolean>();
private readonly editMode$: Observable<boolean> = this.editMode.asObservable();
Expand Down Expand Up @@ -77,6 +74,7 @@ export class EditableComponent implements OnInit, OnDestroy {

private handleEditMode(): void {
const clickOutside$ = fromEvent(document, this.closeBindingEvent).pipe(
skip(this.openBindingEvent === 'click' ? 1 : 0),
filter(({ target }) => this.element.contains(target) === false),
take(1)
);
Expand Down
3 changes: 2 additions & 1 deletion src/app/app.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,8 @@ <h4>Table example</h4>
(cancel)="cancel(index, 'isActive')"
>
<ng-template viewMode>
{{ account.isActive }}
<!-- nested value for testing purposes -->
<span>{{ account.isActive }}</span>
</ng-template>
<ng-template editMode>
<input placeholder="isActive" type="checkbox" [formControl]="getControl(index, 'isActive')" />
Expand Down

0 comments on commit 07c8262

Please sign in to comment.