如何在ui-grid中包含angular-uib星级?

时间:2016-02-03 08:50:03

标签: angularjs-directive angular-ui-bootstrap angular-ui-grid

我一直在尝试使用celltemplate字段在ui网格中包含uib星级,但它会返回错误" Uncaught SyntaxError:意外的标识符"。 经过一些调试后我发现它无法理解celltemplate中给出的uib-rating指令。(我已经包含了tpls.js)

 $scope.gridOptions.columnDefs = [
    { name:'FirstName', width:100, enableCellEdit: true },
    { name:'Rating', width:75, 
        cellTemplate:'<div ng-controller="RatingDemoCtrl"><h4>Default</h4><uib-rating ng-model="rate" max="max" readonly="isReadonly" on-hover="hoveringOver(value)" on-leave="overStar = null" titles="['one','two','three']" aria-labelledby="default-rating"></uib-rating></div>' 
    },
    { name:'Age', width:50 , enableCellEdit: true },
    { name:'Gender', width:75 , enableCellEdit: true },
    { name:'Salary', width:75, enableCellEdit: true }
  ];

1 个答案:

答案 0 :(得分:0)

您的模板可以像下面的代码一样:

<div class="ui-grid-cell-contents">
    <uib-rating ng-model="row.entity.Rating" max="10" readonly="isReadonly">
    </uib-rating>
</div>

在ui-grid模板中,您可以将字段值称为row.entity.[fieldname]。办理登机手续:https://github.com/angular-ui/ui-grid/wiki/Templating

检查此工作示例:

http://plnkr.co/edit/59ToE2XWD9pXlD6tjpDs