I need to add dynamically a button to my html code. The thing is that it has an angular link inside and it dosen't work once the page loads. I've been researching and it looks like I need to use $compile in order to make it work.
Here the two codes I tried:
CODE 1
angular.injector(['ng']).invoke(['$compile', '$rootScope', function(compile, rootScope){
var scope = rootScope.$new();
var result = compile('<a ui-sref="app.form.matter({method:\'new\',id:\'\'})" type="button" class="btn dark_blue_bomhard m-b-5 nuevocliente" >New matter</a>')(scope);
scope.$digest();
$("div.toolbar").append(result);
}]);
This code gives me no error and even puts the button where it has to be, but the link still dosen't works.
CODE 2
angular.element("div.toolbar").append($compile('<a ui-sref="app.form.matter({method:\'new\',id:\'\'})" type="button" class="btn dark_blue_bomhard m-b-5 nuevocliente" >New matter</a>'))(scope);
This second line of code gives me an error: "ReferenceError: $compile is not defined"
I have both codes (not at the same time) in the controller.
Any ideas?
ui-routein the injector.