angular2-ngmodel

How to show placeholder (empty option) in select control in Angular 2?

安稳与你 提交于 2019-11-27 00:45:08
问题 I have this code in my template: <select [ngModel]="selectedSubSectionId" (ngModelChange)="onSubSectionChange($event)"> <option *ngFor="let subSection of event.subSections" [ngValue]="subSection.id">{{ subSection.name }}</option> </select> In my component: public selectedSubSectionId: any; public onSubSectionChange(subSectionId: any) { // some code I execute after ngModel changes. } This works ok, but at the beginning I have an empty box. I want to show a placeholder message there. How can I

Angular 2 ngModel in child component updates parent component property

南笙酒味 提交于 2019-11-26 22:20:11
问题 I made a simple UI which consist two components (parent and child). What the UI does is that when I type some stuff in the input box of the Child component. The value will change using ngModel. The child component works fine that way. // Child Component @Component({ selector: 'child', template: ` <p>{{sharedVar}}</p> <input [(ngModel)]="sharedVar"> ` }) export class ChildComponent { sharedVar: string; } Now I have a parent component which I intend to use the same value as Child Component. I

Using Pipes within ngModel on INPUT Elements in Angular

家住魔仙堡 提交于 2019-11-26 03:18:36
问题 I\'ve an HTML INPUT field. <input [(ngModel)]=\"item.value\" name=\"inputField\" type=\"text\" /> and I want to format its value and use an existing pipe: .... [(ngModel)]=\"item.value | useMyPipeToFormatThatValue\" .... and get the error message: Cannot have a pipe in an action expression How can I use pipes in this context? 回答1: You can't use Template expression operators(pipe, save navigator) within template statement: (ngModelChange)="Template statements" (ngModelChange)="item.value |