Custom input and output on same name in Angular2 2 way binding
For this compact syntax to work the input and output need to follow specific naming rules
[(mobile)]="myParam"
@Output('mobileChange') emitter: EventEmitter<string> = new EventEmitter<string>();
@Input('mobile') set setMobileValue(value) {
this.msisdn_confirm = this.msisdn = value;
}
Renaming inputs and outputs by passing a string parameter to the decorator is discourages. Rather use
@Output() mobileChange: EventEmitter<string> = new EventEmitter<string>();
@Input() set mobile(value) {
this.msisdn_confirm = this.msisdn = value;
}
Another example of Gunter's code above that may help:
export class TaskBook {
public taskBookID: number;
public title: String;
}
Inside component code:
....
<input type="text" pInputText [(ngModel)]="data!.title" (change)="onDataChange()" />
....
@Component({
selector: 'taskbook_edit',
templateUrl: './taskbook_edit.component.html'
})
export class TaskbookEditComponent {
@Input() data: TaskBook;
@Output() dataChange = new EventEmitter<TaskBook>();
constructor() { }
onDataChange() {
this.dataChange.emit(this.data);
}
}
Outside in calling component:
<taskbook_edit [(data)]="taskbookObj" ></taskbook_edit>
public taskbookObj: TaskBook;