I am attempting to utilize angularJS in order to dynamically load content from my HTML using ajax calls. My goal is to create a single method that can handle different parameters to specify the ajax/REST uri and display the results in various components. Below is a snippet of the (non-functional) code I have been working on:
app.controller('ContentController', function($scope, $sce, $http) {
$scope.FetchContent = function(pageId) {
let contentUri = 'https://somewhere/restendpoint/?id=' + pageId;
$http.get(contentUri).then(function(data) {
return $sce.trustAsHtml(data.data.d[0].Content);
}
}
})
<div ng-controller="ContentController" class="row">
<div class="col-md-4" ng-bind-html="FetchContent('home')"></div>
<div class="col-md-4" ng-bind-html="FetchContent('welcome')"></div>
<div class="col-md-4" ng-bind-html="FetchContent('contact')"></div>
</div>
However, this implementation is generating numerous ajax calls which is not ideal. I have tried creating a custom directive, but it updates all elements with the same data. Can anyone offer some guidance or advice on how to resolve this issue? Thank you!