ngmodel

Angular 4, How to update [(ngModel)] with a delay of 1 seconds

你说的曾经没有我的故事 提交于 2019-12-03 12:13:04
问题 Since ngModel is updating instantly how to put a delay. <input type="text" value="{{item.task_name}}" name="task_name" [(ngModel)]="item.task_name" (ngModelChange)="update_fields([item.task_name])" > I need to save the task_name with a delay of one seconds by calling update_fields() , To avoid instant calls to service. Thanks 回答1: Rxjs and Observables are the perfect candidate for this type of task! Here is an example of how it can be achieved: Template: <input type="text" [value]="item.task

How to set default selected values in multiselect with ngModel in Angular 2

╄→гoц情女王★ 提交于 2019-11-30 16:12:37
问题 How to set default selected values in multiselect. I get current_options and all_options from database and I want to update current_options and send new values do database again. Updating database works but when I refresh page none of options are selected. current_options = [{id:1, name:'name1'}]; #from database all_options = [{id:1, name:'name1'},{id:2, name:'name2'}]; #from database My template: <select multiple name="type" [(ngModel)]="current_options"> <option *ngFor="let option of all

Change on ngModel reflecting on same ngModel of other browser angular2

时间秒杀一切 提交于 2019-11-29 12:57:32
I am new to angular 2 and creating a project on it. I am using npm to run angular 2 application. Currently, I am hosting application on localhost with 3000 port. Problem in my project is that when I am visiting same page simultaneously on two different browser say crome and firefox. When I am typing on input on one browser, The other browser also reflecting same text on that input. Even input type password also reflecting same. I checked in console and it is showing nothing and searched on web but not found any thing near to this problem. Please help me to know: why different browser

How properly bind an array with ngModel in angular 4?

二次信任 提交于 2019-11-29 08:41:59
Let's suppose I have an array [1,2,3]. I want to iterate all items and bind each to ngModel. When I run this code after changing the first element, the second one is getting the same value. What's the problem? <div *ngFor="let x of array; let i = index;"> <input type="number" [(ngModel)]="x[i]"> </div> ngFor by default uses object identity to compare values, this breaks when primitive values (number, string, boolean) are used, because they change identity when modified). Using trackBy allows to configure ngFor to zse the index instead of identity: <div *ngFor="let x of array; let i = index

Change on ngModel reflecting on same ngModel of other browser angular2

梦想的初衷 提交于 2019-11-28 06:53:14
问题 I am new to angular 2 and creating a project on it. I am using npm to run angular 2 application. Currently, I am hosting application on localhost with 3000 port. Problem in my project is that when I am visiting same page simultaneously on two different browser say crome and firefox. When I am typing on input on one browser, The other browser also reflecting same text on that input. Even input type password also reflecting same. I checked in console and it is showing nothing and searched on

How properly bind an array with ngModel in angular 4?

寵の児 提交于 2019-11-27 19:00:46
问题 Let's suppose I have an array [1,2,3]. I want to iterate all items and bind each to ngModel. When I run this code after changing the first element, the second one is getting the same value. What's the problem? <div *ngFor="let x of array; let i = index;"> <input type="number" [(ngModel)]="x[i]"> </div> 回答1: ngFor by default uses object identity to compare values, this breaks when primitive values (number, string, boolean) are used, because they change identity when modified). Using trackBy