如何使用angular js-ng网格在其中一列网格中显示图像



我对angular JS完全陌生,请告诉我如何使用angular JS将图像显示为网格中某列的值。

如果我答对了你的问题,你可以将img标记绑定到角网格作为单元格模板。我为你制作了一个Plunker。检查一下http://plnkr.co/edit/YIBa7np3kjip2Zzx7nBB?p=preview

var app = angular.module('app', ['ngTouch', 'ui.grid', 'ui.grid.edit']);
app.controller('MainCtrl', ['$scope','$sce', function ($scope,$sce) {

$scope.img="<img ng-src={{url}} />";
$scope.img="<img src='https://angularjs.org/img/AngularJS-large.png' />";
$scope.gridOptions = {
        enableSorting: true,
        columnDefs: [
          { name:'firstName', field: 'first-name' },
          { name:'1stFriend', field: 'lastName' },
          { name:'city', field: 'company'},
          { name:'getZip', field: 'employed', enableCellEdit:true},
          { name:'Photo', field:'photoP' ,cellTemplate:"<img src='https://angularjs.org/img/AngularJS-large.png' />"}
        ],
         data : [
          { 
              "first-name": "Cox",
              "lastName": "Carney",
              "company": "Enormo",
              "employed": true,
              "photoP":""
          },
          {
              "first-name": "Lorraine",
              "lastName": "Wise",
              "company": "Comveyer",
              "employed": false,
              "photoP":""
          },
          {
              "first-name": "Nancy",
              "lastName": "Waters",
              "company": "Fuelton",
              "employed": false,
              "photoP":""
          }
        ]
      };
}]);

最新更新