I want to give id dynamically to the button element of this HTML template which I'm creating in JS file. How can I do that. Help needed.
var template = '<div class="boxTemplate clearfix myDirective"><div class="imageBox ' + imageLayoutType + '">' +
'<img src="' + image + '" />' +
'<div class="tile-title"><span>' + data[dm.title] + '</span></div>' +
'<button class="btn-link favorite glyphicon glyphicon-bookmark"></button>' +
'</div></div>';
Directive code:-
app.directive('myDirective', function() {
var uniqueId = 1;
return {
restrict: 'E',
scope: true,
template: '<button class="btn-link favorite glyphicon glyphicon-bookmark"></button>',
link: function(scope, elem, attrs) {
var item = 'bm' + uniqueId++;
elem.find('button').attr('id' , item);
}
};
});
How can I change the code to make It work It In my favour.