I've encountered a challenge with Angular that I can't seem to solve on my own. I have a news page that will be filled with various types of news, such as weather updates and breaking news. Each piece of news has its own unique template.
My Angular controller utilizes AJAX to fetch the news in JSON format, and I'm using ng-repeat to display this news on the user's screen. Additionally, I'm employing a directive for this purpose. The issue arises when a news item brought in by AJAX looks like this:
news: {
title: "sdijfdslfkndc",
template: "default_template.html",
....
}
And in the ng-repeat loop:
<div ng-repeat="info in news">
<info-directive template="info.template"></info-directive>
</div>
I want the infoDirective to utilize the correct template specified in the current news item. The problem is that the info.template attribute is being treated as a String rather than an object.
If anyone has any insights or suggestions on how to address this issue, I would greatly appreciate it!
Goodbye for now!
PS: Just to give you a glimpse of my infoDirective:
app.directive('infoDirective', function() {
return {
restrict: 'E',
scope: {
template: '='
},
templateUrl: template
};
});