Hello friends,
I’m junior developer in ionic and I do maintenance for existing app.
I want to add ‘like’ button like in facebook to feed in my app - are there any example how I can do it easly?
I use ionic v1.
Thanks!
Jur
Hello friends,
I’m junior developer in ionic and I do maintenance for existing app.
I want to add ‘like’ button like in facebook to feed in my app - are there any example how I can do it easly?
I use ionic v1.
Thanks!
Jur
Hi,
You can do that by adding a like button on the template and then add some logic in the controller.
for example assuming you have ng-repeat:
<div ng-repeat="item in array">
`<button ng-click="likeMe($index)" ng-class="{'liked':item['liked']}">like</button>`
</div>
Also you can add hide show or add class to a different icon, it depends on the project.
in controller:
$scope.likeMe = (idx)=>{
//make http call request to server and add/increase likes for that topic or whatever.
//when the response back is successful then update the property on that button.
service.addLike(topicId, someValue, userId).then((isDone) => {
if (isDone) {
$scope.array[idx]['liked'] = true;
} else {
// something is off.
}
}, error = () => {
})
}
Then in style.css add the some style to make the button looks like it was clicked or you can disable the button by ng-disabled or do what ever the project requires.