ng-grid不适用于文件引用的单元格模板

时间:2022-06-25 19:41:29

I am using angular-js + ng-grid and for some columns I want to use cell-templates. But for some reason it doesn't want to work when template-html is stored and referenced as a file.

我正在使用angular-js + ng-grid,对于某些列,我想使用cell-templates。但由于某些原因,当template-html存储并作为文件引用时,它不希望工作。

    columnDefs: [ { 
       field: "Foo", 
       displayName: "Foo", 
       cellTemplate: '<div class="ngCellText"><input type="text" ng-model="row.entity[col.field]"/> </div>' 
    }] // OK

    columnDefs: [ { field: "Foo", displayName: "Foo", cellTemplate: 'cellTemplate.html' } ]
    // Error: [$parse:syntax] Syntax Error

Moreover, if I follow a link to plunkr from their site I see that it doesn't work as well. ( you can follow the link to see the exact error text ).

此外,如果我从他们的网站上关注plunkr的链接,我发现它不起作用。 (您可以点击链接查看确切的错误文本)。

1 个解决方案

#1


2  

Seems to work if you give the external template another name than the one that is already in the $templateCache.

如果您为外部模板提供的名称不是$ templateCache中已有的名称,那么似乎可以工作。

    $scope.gridOptions = {
    data: 'myData',
    columnDefs: [{
        field: 'name',
        displayName: 'Name'
    }, {
        field: 'age',
        displayName: 'Age',
        cellTemplate: "exCellTemplate.html"
    }]
    };

Working Plunker

#1


2  

Seems to work if you give the external template another name than the one that is already in the $templateCache.

如果您为外部模板提供的名称不是$ templateCache中已有的名称,那么似乎可以工作。

    $scope.gridOptions = {
    data: 'myData',
    columnDefs: [{
        field: 'name',
        displayName: 'Name'
    }, {
        field: 'age',
        displayName: 'Age',
        cellTemplate: "exCellTemplate.html"
    }]
    };

Working Plunker