I am trying to populate a table based on an array of objects. This array does not contain objects of the same type, and for each row I need a completely different style and the onclick function, basically, a completely different behavior. For instance,
var data=[
{
type:'dir-b',
data: { ... }
},
{
type:'dir-b',
data: { ... }
},
{
type:'dir-c',
data: { ... }
}
]
For the dirB object type, I need a template and controller, and for dirC, a completely different function and template.
I found a solution to create 3 directives. One of them will work to define one of the other two directives to add based on the data.
.directive("dirA", function($compile){
return{
restrict:'A',
priority:1000,
terminal:true,
link: function(scope, element, attribute){
element.removeAttr("dir-a");
element.attr(attribute.type,"");
$compile(element)(scope);
}
}
})
.directive("dirB", function($compile){
return{
restrict:'A',
replace:true,
link: function(scope, element, attribute){
console.log("dirA");
}
}
})
.directive("dirC", function($compile){
return{
restrict:'A',
replace:true,
link: function(scope, element, attribute){
console.log("dirC");
}
}
});
<tr dir-a type='{{d.type}}' ng-repeat='d in data'/> . dirA 0, , , , 1000, b.type .
- ?