ng-blur事件在ui-grid单元模板上不起作用

时间:2016-02-05 16:38:57

标签: angularjs angular-ui-grid

以下是示例代码。我在ui-grid中有一个单元格模板(文本框)。我希望在文本框的值发生变化时使用ng-blur事件,但此事件不会触发。

 {
    name: "Amount", displayName: "Amount", enableFiltering: false,

    cellTemplate: '<input type="text" ng-model="row.entity.Amount" ng-blur="updateEntity(row.entity)"></input>'
 }

是否有人跨越此场景或在ui-grid的单元格模板中使用了ng-blur。谢谢。

1 个答案:

答案 0 :(得分:1)

你可以使用原生api:

$scope.gridOptions.onRegisterApi = function(gridApi){
     //set gridApi on scope
     $scope.gridApi = gridApi;
     gridApi.rowEdit.on.saveRow($scope, $scope.saveRow);
};

$scope.saveRow = function( rowEntity ) {
// create a fake promise - normally you'd use the promise returned by $http or $resource
var promise = $q.defer();
$scope.gridApi.rowEdit.setSavePromise( rowEntity, promise.promise );

// or call your logics here with returning promise.reject() - on error or promise.resolve() - on success

// fake a delay of 3 seconds whilst the save occurs, return error if gender is "male"
$interval( function() {
  if (rowEntity.gender === 'male' ){
    promise.reject();
  } else {
    promise.resolve();
  }
}, 3000, 1);

教程链接http://ui-grid.info/docs/#/tutorial/205_row_editable