【问题标题】:Angular ng-grid editableCellTemplate throwing exceptionAngular ng-grid editableCellTemplate 抛出异常
【发布时间】:2013-08-26 09:46:51
【问题描述】:

我正在尝试在 ng-grid (documented here) 中设置 editableCellTemplate ColumnDef 选项。

当我设置它时,即使是默认值<input ng-class="'colt' + col.index" ng-input="COL_FIELD" />,点击一个单元格会立即出现错误

错误:没有控制器:ngModel 在错误() 在 getControllers (http://foo.com:43037/Scripts/angular.js:4232:19) 在 nodeLinkFn (http://foo.com:43037/Scripts/angular.js:4361:35) 在compositeLinkFn (http://foo.com:43037/Scripts/angular.js:3969:15) 在compositeLinkFn (http://foo.com:43037/Scripts/angular.js:3972:13) 在 publicLinkFn (http://foo.com:43037/Scripts/angular.js:3874:30) 在对象。 (http://foo.com:43037/Scripts/ng-grid-2.0.7.js:2660:13) 在 Object.applyFunction [as fn] (:778:50) 在 Object.Scope.$digest (http://foo.com:43037/Scripts/angular.js:7896:27) 在 Object.$delegate.proto.$digest (:844:31)

如果我不设置editableCellTemplate,编辑单元格就可以了。

$scope.gridOptions = {
    data: 'people',
    enableCellSelection: true,
    enableRowSelection: false,
    enableCellEdit: true,
    columnDefs:
    [
        { field: 'Id', displayName: 'ID', enableCellEdit: false },
        { field: 'Name', enableCellEdit: true, 
          editableCellTemplate: '<input ng-class="\'colt\' + col.index" ng-input="COL_FIELD" />' }
    ]
};

怎么了?

(我实际上要解决的问题是creating an event when cell edit ends,但该解决方案假定您可以设置单元格模板)

【问题讨论】:

    标签: javascript angularjs ng-grid


    【解决方案1】:

    input 的模板还需要定义 ng-model 属性:

    <input ng-class="'colt' + col.index" ng-input="COL_FIELD" ng-model="COL_FIELD" />
    

    这是defaulteditableCellTemplate。

    【讨论】:

    • 这很好用,谢谢。我得到的“默认”值是从 API 文档angular-ui.github.io/ng-grid/#api 复制粘贴的,它缺少 ng-model 属性。对我来说看起来像是一个文档错误。
    • 谢谢!这确实有效.. 但我想了解为什么我必须同时使用 ng-model 和 ng-input:它们的确切含义是什么?
    • 完全同意 Luke,对于 editableCellTemplate 的值有很多神奇的咒语。什么是'colt'#?什么是 COL_FIELD?什么是 ng-input?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-11-06
    • 1970-01-01
    • 2013-05-24
    • 1970-01-01
    • 1970-01-01
    • 2011-05-30
    相关资源
    最近更新 更多