When you create the element and set the attributes using your method, please compile the new content using $compile and then append.
var aTag1 = document.createElement('a');
aTag1.innerHTML = 'testing'
aTag1.setAttribute('ng-click', "setID(" + "'test'" + ")");
var test = $compile(aTag1)(scope);
element.append(test);
Please check the below working example, also this logic should be done inside an angular directive, since we are modifying the element.
angular.module('components', []).directive('helloWorld', function($compile) {
return {
restrict: 'E',
scope: {
name: '='
},
template: '<span>Hello {{name}}</span>',
link: (scope, element, attrs) => {
var aTag1 = document.createElement('a');
aTag1.innerHTML = 'testing'
aTag1.setAttribute('ng-click', "setID(" + "'test'" + ")");
var test = $compile(aTag1)(scope);
element.append(test);
scope.setID = function(value) {
console.log(value);
}
}
}
})
angular.module('myApp', ['components']).controller('myctrl', ['$scope', function($scope) {
$scope.name = 'test';
}]);
.ng-scope {
border: 1px red solid;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.6.6/angular.min.js"></script>
<div ng-app="myApp" ng-controller='myctrl'>
<hello-world name="name"></hello-world>
<div>