0
I have a Directive that within it has a list. This list is populated after the successful response of an ajax call. For this reason my Directive link function does not find this list as soon as the page loads, only when it finishes loading the ajax.
How do I apply click events to that list once I get the ajax response?
Code of the Directive:
function localizationFilter(){
var directive = {
restrict: 'E',
replace: true,
scope: true,
templateUrl: 'template.html',
scope: {
controller: '=',
list: '='
},
compile: function(tElement, attr){
return function(scope, elem, attrs) {
var checks = elem.find('li')
console.log(checks) // não encontra nada
}
}
}
return directive
}
Template of the Directive:
<ul class="filter-subitens-list">
<li ng-repeat="item in list">
<input type="checkbox" id="{{item + $index}}" value="{{item.name}}">
<label for="{{item.name + $index}}">
{{item.name}} <span>{{item.total}}</span>
</label>
</li>
</ul>
But in my case I need to call a function by clicking on the checkbox. I create this function in the controller or in Directive?
– Felipe Coelho
@Felipecoelho you create in the controller.
– HENRIQUE LOBO