0

can anyone helping me about showing just value of property in angular,

code snippet in my html :

<p>{{ tag }}</p>

code snippet in my controller.js :

var resource = $resource('/about');
resource.query(function(result){
  $scope.tag = result;  
});

I'm using mongodb for database which contain data {'name':'blablablablabla'}, when I run this code i get [{'name':'blablablablabla'}] in my browser, this is not what i want, i just want showing name value which is 'blablablabla' in html

4 Answers 4

2

Try accessing the name property directly:

$scope.tag = result[0].name;
Sign up to request clarification or add additional context in comments.

Comments

2

[{'name':'blablablablabla'}] is an array containing 1 object inside. To access the name property of this object you can simply assign it as

$scope.tag = result[0].name;

Comments

1

You get as result the entire JSON returned from your MongoDB. What you want is to get just the name, so:

$scope.tag = result[0].name;

Comments

1

You need a forEach on result, and $scope.tag will be:

$scope.tag = result[index].name;

Your array result must have only one element.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.