首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用变量时角云宽度不起作用

使用变量时角云宽度不起作用
EN

Stack Overflow用户
提问于 2020-11-08 14:37:44
回答 3查看 143关注 0票数 2

我对使用角云有一个问题。如果我添加这样一个简单的图像:

代码语言:javascript
复制
<cl-image class="img-fluid" [public-id]="brand.image.publicId" dpr="auto" crop="scale">
    <cl-placeholder type="pixelate">
    </cl-placeholder>
    <cl-transformation quality="auto" fetch-format="auto" width="500">
    </cl-transformation>
</cl-image>

这个很好用。如果我尝试添加一个宽度:

代码语言:javascript
复制
<cl-image class="img-fluid" [public-id]="brand.image.publicId" dpr="auto" crop="scale">
    <cl-placeholder type="pixelate">
    </cl-placeholder>
    <cl-transformation width="150" crop="thumb">
    </cl-transformation>
    <cl-transformation quality="auto" fetch-format="auto" width="500">
    </cl-transformation>
</cl-image>

这也很管用。但我希望我的宽度是一个变量,而不是静态宽度。因此,我更新了代码如下:

代码语言:javascript
复制
<cl-image class="img-fluid" [public-id]="brand.image.publicId" dpr="auto" crop="scale" *ngIf="width">
    <cl-placeholder type="pixelate">
    </cl-placeholder>
    <cl-transformation [width]="width" crop="thumb">
    </cl-transformation>
    <cl-transformation quality="auto" fetch-format="auto" width="500">
    </cl-transformation>
</cl-image>

但这不管用。它显示图像,但没有调整大小,这是不好的。注意这一行:

代码语言:javascript
复制
<cl-transformation [width]="width" crop="thumb">

就像它被忽略了一样,我还确保在使用*ngIf="width"设置宽度之前不会创建组件。

有人知道为什么这不管用吗?

EN

回答 3

Stack Overflow用户

回答已采纳

发布于 2020-11-09 17:58:32

在您的app.component.ts上,您可以声明变量,例如:

代码语言:javascript
复制
public imageHeight = "500";
public imageQuality = "50";

然后在app.component.html中,在cl-transformation元素中,需要使用关键字attr.

代码语言:javascript
复制
<cl-transformation
  attr.height="{{imagesize}}"
  crop="scale"
  attr.quality="{{imagequality}}"
>

CodeSandBox演示

票数 2
EN

Stack Overflow用户

发布于 2020-11-08 17:28:54

我对Cloudinary没有多少经验。也没有测试过它。查看云码,您可以尝试以下几个选项:

  1. 输入组件上使用cl-image。组件有它的定义。
代码语言:javascript
复制
export class CloudinaryImage
  implements AfterViewInit, OnInit, AfterViewInit, AfterContentChecked, OnChanges, OnDestroy {
  @Input('public-id') publicId: string;
  @Input('client-hints') clientHints?: boolean;
  @Input('loading') loading: string;
  @Input('width') width?: string;
  @Input('height') height?: string;
  1. 如果这不是您想要的,那么查看cl-变换指令,您似乎只能传递本地属性。
代码语言:javascript
复制
export class CloudinaryTransformationDirective {

  constructor(private el: ElementRef) {
  }

  getAttributes(): NamedNodeMap {
    return this.el.nativeElement.attributes;
  }
}

这意味着,为了将动态值传递给指令元素属性,也许可以使用内插

代码语言:javascript
复制
<cl-transformation width="{{ width }}" >
票数 0
EN

Stack Overflow用户

发布于 2020-11-08 21:06:42

我对棱角不太熟悉,但你可以尝试以下方法,直到有更熟悉的人出现为止:

<cl-transformation width={{width}} crop="thumb">

传入硬编码的整数可以工作,因此只要定义了width并将其作为整数,它就可能工作。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/64739314

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档