I am trying to create a \'like\' function for my app. I want to be able to set the value of a dynamically generated number as the \'like count\'. The problem comes in using \'ng
Just change
`{{likeCount}}`
per
`{{feed.likes.length}}`.
If you still need the count in the controller for some other reason (which I can't see), create a controller, let's assume FeedCtrl
, and add it to your article
:
...
{{likeCount}}
And your FeedCtrl would be:
function FeedCtrl($scope) {
$scope.$watch('feed.likes.length', function(newValue) {
$scope.likeCount = newValue;
});
}
Yet another approach would be create a function to resolve you the value:
...
{{likeCount()}}
function FeedCtrl($scope) {
$scope.likeCount = function() {
return $feed && $feed.likes ? $feed.likes.length : undefined;
};
}