Skip to content

Instantly share code, notes, and snippets.

@matthieu-D
Created September 5, 2017 14:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save matthieu-D/3d8ebe8702dc09bc085c42eda4286e7b to your computer and use it in GitHub Desktop.
Save matthieu-D/3d8ebe8702dc09bc085c42eda4286e7b to your computer and use it in GitHub Desktop.
import {Component, Input, EventEmitter, Output } from '@angular/core';
@Component({ selector: 'editable-text', template:`
<span *ngIf='isEditable'> <input type='text' (blur)="updateParent()" [(ngModel)]='writableData.name'></span>
<span *ngIf='!isEditable' (click)='setEditable(true)'> {{writableData.name}} </span>
`
})
export class XEditableText {
writableData = {};
@Input() data;
@Output('updateUser') updateUser: EventEmitter<any> = new EventEmitter<any>();
isEditable:boolean;
ngOnInit() {
Object.assign(this.writableData, ...this.data);
this.isEditable = false;
}
setEditable(isEditable){
this.isEditable = isEditable;
}
updateParent() {
this.setEditable(false);
this.updateUser.emit(this.writableData);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment