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="{{group.members.length}}" ng-hide="$index>=0">
</td>
<td>{{member.taskName}}</td>
<td><div class={{group.colorMe[0]}}>{{member.env}}</div>
<button class="btn btn-info" ng-controller="member.taskName" ng-click="test( member.taskName , 'env', group.colorMe[0])">Sanity</button>
</td>
And my main Controller looks like this where the groups are defined as this :
var tasks =['task1','task2','task3','task4','task5'];
for(i=0;i<tasks.length;i++)
{
var group = {
"id" : i+1,
"members" : [{
"taskName":tasks[i].toUpperCase(),
"env1":versionMap["env1"+tasks[i]],
"env2":versionMap["env2"+tasks[i]],
"env3":versionMap["env3"+tasks[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.taskName . Can someone please help me with this?
You need to add some extra logic to your service. So it will require new dependencies such as:
$controller
,$compile
,$root$scope
or$scope
. And optional one$templateCache
. Templates are optional as well.DEMO JSFiddle
Dynamic controller service:
More specific code for you:
Directive
Service
HTML
I hope it will help