user3902406
user3902406

Reputation: 19

load differents image in angularjs

I want to show differents image depending of variable value. if the user.ima variable is empty must show defaultImg variable.

<img class="" ng-src="{{this value depend of user.ima if empty then load defaultimg}}" width="60px" >

Upvotes: 1

Views: 39

Answers (1)

Amir Popovich
Amir Popovich

Reputation: 29836

Use a method:

$scope.GetImgUrl = function(){
   if(!$scope.user.ima)
   {
      return $scope.defaultImgUrl;
   }

   return $scope.user.ima;
}

And:

<img class="" ng-src="{{GetImgUrl()}}" />

Upvotes: 2

Related Questions