I am just starting to learn AngularJS, particularly the asynchronous programming paradigm, and I'm currently working on my first AngularJS project. While I understand the basics and fundamentals, I have encountered a challenge.
Issue: I need to create a directive only when certain data is available, which is fetched asynchronously. The directive is also part of the controller's template. How should I approach this?
My Strategy: I tried using ng-if="variable" on the directive to be created once the data is ready, along with a watch on that variable to initiate the creation process. However, I'm struggling to implement this programmatically! What would be the best way to achieve this or is there a more efficient approach?
Controller
$scope.dataFetched = false;
$http.get(url)
.then(function success(result){
$scope.dataFetched = true;
});
HTML
<span>Hello World</span>
<directive-abc ng-if="dataFetched"></directive-abc>
Also, how does $digest handle the execution of that particular directive after completing the controller template?