ng-change is run initially when the page loading...

45 views
Skip to first unread message

Subha Priya

unread,
Feb 26, 2016, 11:11:50 PM2/26/16
to AngularJS
Hi,
    I have dropdown list. In that, i have function in the ng-change. But it run initially the page loading itself. I want some action while changing the values in the dropdown. Initially dropdown has some value. My code is like

<input id="leave_name" config="selectize_config"
                                        options="selectize_options"
                                        ng-model-options="{ updateOn: 'default blur', debounce: { 'default': 500} }"
                                        ng-change="changeStatus(value.status,value.id)"
                                        ng-model="value.status" selectize />

It runs initially and it send query to the DB also. The same thing i have ng-change function in the datetime picker. But it is not running initially only change it will work.

<input id="time_punchin" name="time_punchin" ng-model="value.time_punchin"
                                        ng-change="attendanceStartTime(value.time_punchin,value.id)"
                                        kendo-date-time-picker k-ng-model="time_punchin" k-options="dateTimePickerOptions">

Someone please help to solve this problem. It affects my performance very badly.

Sander Elias

unread,
Feb 27, 2016, 1:55:46 AM2/27/16
to AngularJS

Hi Subha,

If it has such a big impact on your performance, why do you not check in your function or it’s needed at all? Keep an copy of the old val and do something like ìf (old===new) {return} in the top of your function.

Aside from that, I don’t understand what you are asking, do you want it to fire at startup, or do you need to prevent it??

Regards
Sander

Subha Priya

unread,
Feb 27, 2016, 10:55:39 PM2/27/16
to ang...@googlegroups.com
In dropdown, i have values like active and inactive. Initially it displayed as active. If i'll change it changes in the DB also. If i have 50 users it run 50 times initially. Thats my problem.

--
You received this message because you are subscribed to a topic in the Google Groups "AngularJS" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/angular/eW57YUoPPpI/unsubscribe.
To unsubscribe from this group and all its topics, send an email to angular+u...@googlegroups.com.
To post to this group, send email to ang...@googlegroups.com.
Visit this group at https://groups.google.com/group/angular.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages