根据 angularjs 表达式更改 img 源
change img source based on angularjs expression
所以我试图根据表达式更改图像的来源,看看它是否真实。
HTML
<img ng-src="category.content.Value >= category.content.ValueOneWeekAgo ?
'Images/green_arrow.png' : 'Images/red_arrow.png'" />
这是呈现的 html 的样子:
<img ng-src="category.content.Value >= category.content.ValueOneWeekAgo ? 'Images/green_arrow.png' : 'Images/red_arrow.png'"
src="category.content.Value >= category.content.ValueOneWeekAgo ? 'Images/green_arrow.png' : 'Images/red_arrow.png'">
我知道变量包含已通过调试确认的值。可能是一些简单的东西,但我似乎无法弄明白。
您可以将表达式中的顺序切换为使用 <
而不是 >=
。
您不能使用 >=
,因为浏览器将其视为 html 标记的结尾。
<img ng-src="category.content.ValueOneWeekAgo < category.content.Value ? 'Images/green_arrow.png' : 'Images/red_arrow.png'" >
其他选项是将此代码放入控制器中并作为新变量发布到 $scope
。
所以我试图根据表达式更改图像的来源,看看它是否真实。
HTML
<img ng-src="category.content.Value >= category.content.ValueOneWeekAgo ?
'Images/green_arrow.png' : 'Images/red_arrow.png'" />
这是呈现的 html 的样子:
<img ng-src="category.content.Value >= category.content.ValueOneWeekAgo ? 'Images/green_arrow.png' : 'Images/red_arrow.png'"
src="category.content.Value >= category.content.ValueOneWeekAgo ? 'Images/green_arrow.png' : 'Images/red_arrow.png'">
我知道变量包含已通过调试确认的值。可能是一些简单的东西,但我似乎无法弄明白。
您可以将表达式中的顺序切换为使用 <
而不是 >=
。
您不能使用 >=
,因为浏览器将其视为 html 标记的结尾。
<img ng-src="category.content.ValueOneWeekAgo < category.content.Value ? 'Images/green_arrow.png' : 'Images/red_arrow.png'" >
其他选项是将此代码放入控制器中并作为新变量发布到 $scope
。