When I retrieve news with a specific id from my REST API, using ng-repeat to display all news works fine. However, when I try to display a single object, this method does not work.
My route code:
.when('/displaynews/:id',{
templateUrl: 'views/display.html',
controller: 'NewsDisplayController',
controllerAs: 'displaydash'
})
and the controller code:
.controller('NewsDisplayController',
function($routeParams, NewsModel){
var displaydash = this;
var newsId = $routeParams.id;
path = 'getNewsById/'+newsId;
function getNewsById() {
NewsModel.getNewsById().then(function (result){
displaydash.news = result.data;
console.log(displaydash.news);
})
}
getNewsById();
})
Result from console.log:
Object { id="56f1ba6b275c8aa5bf4895d8", title="Tytul", text="Text", more...}
How can I display this in my HTML template?
I have tried displaying in the HTML file this way:
<p>{{news.title}}</p>
<p>{{news.text}}</p>
But it is not working