I am executing an ajax call which fetches some information:
<span id="test" abc-dir="test"> </span>
Now, i also have an angular directive that i need to run on the above information returned via ajax.
Problem is: The Angular directive is getting initiated first and tries to find abc-dir in the DOM however since the Ajax call is not complete, it does nothing. How to fire the ajax call first and then call the Angular directive?
My HTML code:
<body ng-app="TestApp" ng-controller="TestCtrl" ng-init="init()">
<div class="test" id="testid"></div>
<script>
require( ['jquery'], function($) {
$.ajax({
type: "GET",
url: "....",
success: function(data) {
document.getElementById('testid').innerHTML = data
}
});
});
</script>
My Angular directive code is as follows:
angular.module('TestApp', ['ngSanitize'])
.directive('abcDir',['abcPropertyMap',function(abcPropertyMap) {
return {
restrict: 'A',
template: function(elm,attrs){
var value = abcPropertyMap[attrs.abcProperty];
return '<span ng-bind-html="'+value+'">x</span>';
}
}
}])