Okem
Okem

Reputation: 403

showing data in angular

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

Upvotes: 0

Views: 41

Answers (4)

Gabriel Cuenca
Gabriel Cuenca

Reputation: 121

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

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

Your array result must have only one element.

Upvotes: 1

AlexD
AlexD

Reputation: 4310

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;

Upvotes: 1

Moshe Karmel
Moshe Karmel

Reputation: 459

Try accessing the name property directly:

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

Upvotes: 2

Carlos Sultana
Carlos Sultana

Reputation: 709

[{'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;

Upvotes: 2

Related Questions