0

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.

srv
  • 61
  • 1
  • 1
  • 11
  • Make fast a http://plnkr.co/ to make it easier to understand what you want to do. – Bettimms May 19 '16 at 08:29
  • What to you mean by "work in my favour"? What are you trying to accomplish? As written, the code instantiates buttons with unique ids. What else do you want to do? – georgeawg May 19 '16 at 19:59

0 Answers0