gpt4 book ai didi

angular - 什么相当于较新的 Angular 中的 ngSrc?

转载 作者:太空狗 更新时间:2023-10-29 16:45:31 26 4
gpt4 key购买 nike

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

在 AngularJS 中,我可以这样做:

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

在 Angular 2+ 中是否有与此等效的东西?

最佳答案

AngularJS:

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

Angular 2+:

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

Angular docs


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

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

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

这两个属性绑定(bind)语句在技术上没有区别,只要您不希望进行双向绑定(bind)即可。

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 - 什么相当于较新的 Angular 中的 ngSrc?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37965667/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com