3
I want to pull this Json data from the Service by an External Json via $http. I found several examples plus they are not returning result to me.
.service('ProdutosService', function($q) {
return {
produtos: [
{
"nomeProd": "nomeproduto",
"codCat": "nomecategoria",
"id": "01"
},
{
"nomeProd": "nomeproduto2",
"codCat": "nomecategoria2",
"id": "02"
},
],
getProdutos: function() {
return this.produtos
},
getProduto: function(produtoId) {
var dfd = $q.defer()
this.produtos.forEach(function(produto) {
if (produto.id === produtoId) dfd.resolve(produto)
})
return dfd.promise
}
}
});
Can you explain what problem you’re trying to solve? Click [Edit] and add more details to your post.
– Jéf Bueno
i have this json products, plus it’s within the service. I want to pull this json from an external file, using $http.
– Alexandre Scrideli
You want to take this product data from a server?
– DiegoAugusto
i have an external json file and want to pull this json into the service via $http. The file path is js/products.json.
– Alexandre Scrideli
If you want to pull over $http you need to have a server
– DiegoAugusto
within $http.get cannot place a local file. Example: $http.get("js/products.json")
– Alexandre Scrideli
I can’t say for sure, but possibly not. If you have how it will be a great gambiarra, there must be other ways to get this file without http
– DiegoAugusto
and how this json would look on a server. I have this file hosted on a server. How would you pull it into the Service?
– Alexandre Scrideli
For $http. Example:
$http.get("http://pokeapi.co/api/v2/pokemon/4");
– DiegoAugusto
yes.. more as the service structure would look with this $http. I’ve made several attempts but none of them worked.
– Alexandre Scrideli
There are several ways to assemble the service structure, I do it this way: http://pastebin.com/3DMuY1FR
– DiegoAugusto
Note that in $http.get I am using the local ip, where I have a server sending me data in Json format
– DiegoAugusto