Thursday, 27 April 2017

Setting ng-controller dynamically from a variable value

I am developing an application using angularJs and nodejs. Am struck at setting the name of the controller to the value of a variable from main controller. To explain it better, my index.html looks like this :

        <tbody ng-repeat="group in groups">

        <tr ng-repeat="member in group.members" >
            <td rowspan="" ng-hide="$index>=0">
            </td>

            <td></td>
            <td><div class=></div>
                <button class="btn btn-info" ng-controller="dynamic_set_controller" ng-click="test( member.serviceName , 'env', group.colorMe[0])">Sanity</button>
            </td>

And my main Controller looks like this where the groups are defined as this :

  for(i=0;i<services.length;i++)
    {

    var group = {
                  "id" : i+1,
                  "members" : [{
                      "serviceName":services[i].toUpperCase(),
                      "env1":versionMap["env1"+services[i]],
                      "env2":versionMap["env2"+services[i]],
                      "env3":versionMap["env3"+services[i]]

                  }]
                };
              $scope.groups.push(group);
              }

Now when i click the button , I should be direcrted to a particular controller and this controller name needs to be set dynamically to member.servicename . Can someone please help me with this?



via Nagireddy Hanisha

No comments:

Post a Comment