Answer the question
In order to leave comments, you need to log in
How to get value from JSON in Angular Controller?
Good afternoon! There is a question that interests me very much and I can not figure it out in any way. I know how to get JSON array value into HTML file. But for example, I need to get this value directly in the controller, let's imagine a number of posts and they have this id and I want to create a delete button for each post and how can I get this id in the Controller right away?
Is there such an example?
"id": "802",
"component": "blogs",
"type": "new_blog_post",
"user": {
"id": "1",
"username": "admin",
"mail": "[email protected]",
"display_name": "mr. Whale",
"avatar_thumb": "avatars/1/57f4791714aa4-bpfull.jpg",
"is_following": 0
}
Answer the question
In order to leave comments, you need to log in
Let's say you have posts displayed there using ngRepeat :
Add a delete button, hang ngClick on it, where you pass a function from the controller with an argument in the form of an ID.
For example like this:
<span ng-click="vm.removeItem(post.id)">Delete</span>
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question