0

I'm trying to set the name of the ng-controller, through looping an array. However, it seems it's not working. This is the code I have so far:

JS:

var app = angular.module('xmil', ['ngRoute']);

app.controller('mainController', ["$scope", function ($scope) {
    $scope.tabsArray = [{
            numero: '1',
            ControllerName: 'GeneralController',
            grupo: 'General'
        },
        {
            numero: '2',
            ControllerName: 'ParametrosController',
            grupo: 'CEMS'
        },
        {
            numero: '3',
            ControllerName: 'CilindrosController',
            grupo: 'Cilindros'
        },
        {
            numero: '4',
            ControllerName: 'EquiposController',
            grupo: 'Equipos'
        },
        {
            numero: '5',
            ControllerName: 'DPController',
            grupo: 'DP'
        },
        {
            numero: '6',
            ControllerName: 'MPController',
            grupo: 'MP'
        },
    ];
}]);

HTML

<div class="card" ng-repeat="tab in tabsArray">
  <div [ng-controller]={{tab.ControllerName}}></div>
</div>

The purpose of this is to make the HTML code smaller.

How can I achieve to set the values of tab.ControllerName to the ng-controller of each div created?

halfer
  • 19,824
  • 17
  • 99
  • 186
Julio Rodriguez
  • 499
  • 6
  • 16
  • 1
    I don't think that you can use the `[]` syntax in AngularJS. This is an Angular feature. – ChrisY Jan 13 '20 at 19:15
  • Could you please provide me a small example, please? – Julio Rodriguez Jan 13 '20 at 19:18
  • 1
    did not work with AngularJS myself lately. seems as if you have to create a custom `dynamic-ng-controller`directive for this. maybe this answer helps: https://stackoverflow.com/a/51307872/4527675 – ChrisY Jan 13 '20 at 19:24

0 Answers0