在较新的Angular中等效于ngSrc? [英] Whats equivalent to ngSrc in the newer Angular?

查看:72
本文介绍了在较新的Angular中等效于ngSrc?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想用来自JSON对象的src实现img.

I would like to implement img, with a src coming from JSON object.

在AngularJS中,我可以这样做:

In AngularJS, I could do:

<img ng-src="{{hash}}" alt="Description" />

Angular 2+中有与此等效的东西吗?

Is there any equivalent to this in Angular 2+?

推荐答案

AngularJS:

AngularJS:

<img ng-src="{{movie.imageurl}}">

Angular 2 +:

Angular 2+:

<img [src]="movie.imageurl">

角度文档

请注意,插值可以达到相同的结果:

Note that interpolation can achieve the same result:

<img src="{{vehicle.imageUrl}}">

<img [src]="vehicle.imageUrl">

这两个用于属性绑定的语句之间没有技术上的区别,只要您不希望双向绑定即可.

There is no technical difference between these two statements for property binding, as long as you don't desire two-way binding.

插值是许多属性绑定的便捷替代方法 案件.实际上,Angular会将这些插值转换为 呈现视图之前,先进行相应的属性绑定.

Interpolation is a convenient alternative for property binding in many cases. In fact, Angular translates those interpolations into the corresponding property bindings before rendering the view. source

这篇关于在较新的Angular中等效于ngSrc?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆