0

my API returns this value:

{"id":1,"name":"Test"}

In Angular I did this call to retrieve that value:

$scope.supplier = Suppliers.query({supplierId: $routeParams.id});

But now in my template I do this:

{{supplier.name}} 

Even {{ supplier }} does not give me anything.

but this is empty. Why is this the case?

Thanks!

1
  • 1
    share your service or more code that you have in controller, in your case it looks like a promise is not getting resolved, so that could be your problem. Commented Oct 10, 2017 at 12:43

2 Answers 2

1

The query function returns a callback, try this:

Suppliers.query({supplierId: $routeParams.id}, function(suppliers) => {
    $scope.supplier = suppliers[0];
});

Since query returns a list you need to take only the first from the list.

Sign up to request clarification or add additional context in comments.

3 Comments

I had to do it a bit differently: Suppliers.query({supplierId: $routeParams.id}, function(response) { $scope.supplier = response; }); But in this case {{ supplier }} looks like this in the frontend: [{"id":1,"name":"Test"}] - so we have an array with an object, but supplier.name or supplier.0.name does not result in anything :( Any idea? I do not see it :(
Ah I can use {{supplier[0].name}}
Updated my answer :)
0

var supplier = Suppliers.query({supplierId: $routeParams.id},{_id:0,name:1});

$scope.supplier=supplier[0].name;

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.