user2773013
user2773013

Reputation: 3172

advantage of having ng-model-options

i'm new to angular, and strill trying to wrap my head around it. Say that I have a input text field. Upon update of this field, i want to update my database. I have a js function update(content) that i call to update my database.

with this purpose in mind, what is the difference between these two? One is wihtout the ng-model-options.

<input ng-model-options="{ updateOn: 'blur' }" ng-blur="update(item.text)" value="{{item.text}}" type="text">

<input ng-blur="update(item.text)" value="{{item.text}}" type="text">

Upvotes: 0

Views: 94

Answers (1)

amrit_neo
amrit_neo

Reputation: 1759

Try looking on the details of all directive you have used in the Angular Doc.

For your functionality to achieve, you can use ng-change directive, which is triggerd on change on model connected to the input tag, and in the function, you can have ajax call to update the database.

<input ng-model="myModel" ng-change="updateDataBase()">

In Controller :

$scope.updateDataBase = function(){
    //do ajax call and send $scope.myModel  value.
}

Upvotes: 1

Related Questions