1
I’m communicating my website with API of Behance and I have the following script written in Angular 1.5.5:
var app = angular.module('PortfolioApp', []);
app.controller('PortfolioCtrl', function($scope, portfolioFactory) {
portfolioFactory.getBehance()
.then(function onFulfilled(data){
$scope.projetos = data;
$scope.behanceLoaded = true;
})
.catch(function onRejected() {
console.log('Erro no Factory');
});
});
app.factory('portfolioFactory', function($http) {
var getBehance = function() {
var user = 'luandavi';
var apiKey = 'APIKEY';
return $http.jsonp('https://behance.net/v2/users/'+ user +'/projects?api_key='+ apiKey + '&callback=JSON_CALLBACK')
.then(function onFulfilled(response) {
return response.data.projects;
console.log(response.data.projetcs);
});
};
return {
getBehance: getBehance
};
});
And here I show them
<body ng-app="PortfolioApp">
<div ng-controller="PortfolioCtrl" class="grid">
<div ng-repeat="projeto in projetos" class="item">
<img src="{{projeto.covers.original}}">
<h1>{{projeto.name}}</h1>
<p>{{projeto.stats.views}}</p>
</ul>
</div>
<script src="http://code.angularjs.org/1.5.5/angular.js"></script>
<script src="main.js"></script>
</body>
The problem is that this "original" is an image with the original size that was sent to Behance, obviously. I wish I could use one of the thumbnails that the platform itself generates, after my project aired. Of the options that JSON returns, there are the following:
"covers": {
"115": "https://mir-s3-cdn-cf.behance.net/projects/115/ebf44656341149.Y3JvcCwxMzg0LDEwODMsMzcsMA.jpg",
"202": "https://mir-s3-cdn-cf.behance.net/projects/202/ebf44656341149.Y3JvcCwxMzg0LDEwODMsMzcsMA.jpg",
"230": "https://mir-s3-cdn-cf.behance.net/projects/230/ebf44656341149.Y3JvcCwxMzg0LDEwODMsMzcsMA.jpg",
"404": "https://mir-s3-cdn-cf.behance.net/projects/404/ebf44656341149.Y3JvcCwxMzg0LDEwODMsMzcsMA.jpg",
"original": "https://mir-s3-cdn-cf.behance.net/projects/original/ebf44656341149.Y3JvcCwxMzg0LDEwODMsMzcsMA.jpg"
},
But if I use this number in the.cover.404 project for example, the angular shows syntax error. What I can do?
Thanks! It worked, but the console returns this error: GET http://localhost/Luan.digital/%7B%7Bprojeto.covers[404]%7D%7D 404 (Not Found)
– Luan
@Luandavi use ng-src, I edited the answer take a look
– alxwca