I am very (very) new to AngularJS so if you can please explain solutions and suggestions that would help loads!
I am trying to make a directive which is passed a parameter - in my case championID to then use for a API call.
The API call works and returns back the correct data the only issue i am having is trying to put this in the template and return it.
The error message i am getting is
Reference error: championURL is not defined
my directive is below:
.directive('championImage', function() {
return {
restrict: 'E',
link: function($scope, iElm, iAttrs, controller) {
$scope.championId = iAttrs.championId;
$http.get('https://global.api.pvp.net/api/lol/static-data/euw/v1.2/champion/'+ championId +'?champData=image&api_key=<removed for stack overflow>').success(function(data){
$scope.championURL = '<img src="http://ddragon.leagueoflegends.com/cdn/5.22.3/img/champion/'+ data.image.sprite +'"/>';
}).error(function(data){
console.warn('Incorrect username entered or max queries hit');
});
},
template: championURL
};
});
Any ideas where I am going wrong,
Thanks,
Kieran