在angularjs中加载不同的图像

时间:2014-10-18 15:20:15

标签: angularjs

我想根据变量值显示不同的图像。如果user.ima变量为空,则必须显示defaultIng变量。

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

1 个答案:

答案 0 :(得分:2)

使用方法:

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

   return $scope.user.ima;
}

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