There is such an array:

$scope.ChemicalGroups [ ... HashName: "G815D9D3776614A985A4B18E437349DE2" ... ] 

There is such code:

 $scope.ChemicalGroups.forEach(function (chemicalGroup) { var valStrl = chemicalGroup.HashName; chemicalGroup[valStrl] = { enableColumnMenus: false, enableHorizontalScrollbar: 2, enableVerticalScrollbar: 2, data: [] }; }); 

Ie, I can have as many elements as possible in the ChemicalGroups array and for each I need to create a ui-grid. I want to use the HashName field as the grid's unique name (gridOptions).

Html code:

 <div id="{{item.Id}}" class="panel-collapse collapse in"> <div class="panel-body"> <div ui-grid="item[HashName]" class="grid"> </div> </div> </div> 

In this case, an exception is generated, writes: Token '[' is not a valid

It also does not work this way - ui-grid={{item[HashName]}}


I tried to do this:

 $scope.ChemicalGroups.forEach(function (chemicalGroup) { var valStrl = chemicalGroup.HashName; var model = $parse(valStrl); model.assign($scope, { enableColumnMenus: false, enableHorizontalScrollbar: 2, enableVerticalScrollbar: 2, data: [] }); }); 

Html:

 <div id="{{item.Id}}" class="panel-collapse collapse in"> <div class="panel-body"> <div ui-grid="item.HashName" class="grid"></div> </div> </div> 

In this case, in the standard ui-grid.js script , an exception occurs because the string HashName is passed there. Although in $ scope I added an object before it, which is also named as a HashName line - model.assign($scope... (I checked it in $ scope). But this expression: ui-grid = "item.HashName" For some reason, it does not receive an object but a string.

How to make it recognize exactly the object with that name? Is it possible to transfer any javascript expression in ui-grid="" , for example: {{item[HashName]}} , as far as I understand it is impossible to do so. Any suggestions.

  • nothing is clear what you want to do and what you did. ui-grid="item.[HashName]" - here and in the usual javascript there will be a syntax error. - Grundy
  • The extra point has already been removed - endovitskiiy
  • I want for each element of the ChemicalGroups array to generate a grid - endovitskiiy
  • After removing the dot, the error should disappear. Token '[' is not a valid - Grundy

1 answer 1

Since the field name you have is stored in the HashName field of the object. You need to get the object exactly according to the value found in this field:

 <div ui-grid="item[item.HashName]" class="grid"> 
  • So it does not work, it does not even reach this place. var grid = new Grid(options); in ui-grid.js. There are no errors in the console. - endovitskiiy
  • @endovitskiiy, why do you think that does not reach? This entry does exactly what you want: it transfers the value of the field with the key to the value of the field item.HashName - the object you created. If there are no errors, then the problem is somewhere else. Try to make a minimal reproducible example so that you can run it and see what really doesn't work - Grundy
  • does not reach because at me in that place there is breakpoint. And he just does not reach there. - endovitskiiy
  • @endovitskiiy, but where does it reach? - Grundy
  • In ui-grid.js there is a method called createGrid. In this case, it is not called. And this line is var grid = new Grid(options); in this method. - endovitskiiy