I'm having problems assigning a click event to a previously compiled external template, follow the code ...
Policy
angular.module('testeFuncoes').directive('fechaMenu', function($templateRequest, $compile) {
return {
link: function(scope, element, attr) {
$templateRequest("template.html").then(function(html){
var template = angular.element(html);
element.html($compile(template)(scope));
var cnt = $(element).contents();
$(element).replaceWith(cnt);
$('.ctnTeste').trigger('click');
});
},
}
})
Template
<md-menu-bar>
<md-menu>
<div class="ctnTeste" ng-click="openMenu($mdMenu, ev)" style="display: flex; padding: 20px; background-color: black">
<div class="subTeste" style="padding:{{color.red}}px; background-color:rgb(1,10,{{color.red}});"></div>
<div class="subTeste" id="teste"></div>
</div>...
That is, when I inject this template I want to simulate a click on it, but within the link function. When I pass the trigger, it gives me the following error [$ rootScope: inprog] $ digest already in progress, but if I assign the event manually it works, example ...
$('.testebotao').on('click', function() {
$('.ctnTeste').trigger('click');
})