<select class="custom-select"
name="chapter_default[{{x.id}}][media_contents_attributes][{{$index}}][media_type]"
ng-model="chapter_media_content_media_type_default_$parent.$index_$index"
id="chapter_media_content_media_type_default_{{$parent.$index}}_{{$index}}"
ng-change="changeMediaContentTypeDefault(this)"
>
<option value="">Select Media Content
Type</option>
<option ng-repeat="m in
media_content_type_options"
value="{{m}}" ng-selected="m ==
y.media_type ? true : false">
{{m}}
</option>
</select>
Everything is working fine but probalm is why ng-change function calling
automatically please help me to fix this issue.
On Saturday, April 14, 2012 at 11:16:34 AM UTC+5:30, Igor Minar wrote:
>
> The watch fires automatically (and asynchronously via $evalAsync) upon
> registration, this is initialize the watcher and let your code know what
> the initial value is.
>
> If this is undesirable then you can put this check into your save method:
>
> function save(newVal, oldVal) {
> if (newVal === oldVal) return;
> // do stuff here
> }
>
> /i
>
>
> On Fri, Apr 13, 2012 at 8:45 PM, Daniel Nelson <[email protected]
> <javascript:>> wrote:
>
>> I only see this when working with a resource, and I have not been
>> successful in emulating resources in jsfiddle, so please forgive the
>> lack of a fiddle.
>>
>> Account is a resource. The account is retrieved automatically as follows:
>>
>> @AccountCtrl = ($scope, Account, $defer) ->
>>
>> Account.get {}, (account_from_server) ->
>> $scope.account = account_from_server
>> $defer () ->
>> $scope.$watch('account.default_host', $scope.save)
>>
>> The problem is that the watcher triggers $scope.save() immediately
>> upon creating the watcher, without the model being modified since it
>> was retrieved from the server. I even tried putting it in a $defer (as
>> you see here), and giving the $defer a timeout, but whenever the
>> $defer fires and creates the watcher, $scope.save() is called. This is
>> undesirable, because it means that every time the page is loaded, the
>> model is immediately saved.
>>
>> Is there an explanation for this and a way to avoid it?
>>
>> Thank You,
>>
>> Daniel
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "AngularJS" group.
>> To post to this group, send email to [email protected]
>> <javascript:>.
>> To unsubscribe from this group, send email to
>> [email protected] <javascript:>.
>> For more options, visit this group at
>> http://groups.google.com/group/angular?hl=en.
>>
>>
>
--
You received this message because you are subscribed to the Google Groups
"Angular and AngularJS discussion" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/angular.
For more options, visit https://groups.google.com/d/optout.