2014-11-07 34 views
0

我是新來的棱角分明的人,並且試圖把我的頭包裹在它周圍。 說我有一個輸入文本字段。更新此字段後,我想更新我的數據庫。我有一個js函數更新(內容),我打電話更新我的數據庫。擁有ng-model-options的優勢

爲了這個目的,這兩者有什麼區別?一種是沒有ng型號選項 s。

<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"> 

回答

1

嘗試查看您在Angular Doc中使用的所有指令的詳細信息。

爲了實現您的功能,您可以使用ng-change指令,該指令在連接到輸入標籤的模型上發生更改時觸發,並且在函數中,您可以使用Ajax調用來更新數據庫。

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

在控制器:

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