javascript - 使用 NgStyle 的角度设置位置不起作用
问题描述
我在使用 NgStyle 为以下代码设置位置时遇到问题:
<ng-container *ngFor="let handlePosition of handlePositions; let i = index;">
<div [ngStyle]="{'transform': 'translate(' + value + 'px, 0px)'}" class="handle-slider__handle"
[ngDraggable]="fc.enabled"
[lockAxis]="'y'"
[bounds]="handleSlider"
[inBounds]="inBounds"
[position]="{ x: handlePosition, y: 0 }"
(endOffset)="onHandleChange($event, i)"></div>
</ng-container>
似乎 ngStyle 没有对元素应用更改。有人能指出我如何解决这个问题吗?
@EDIT我已经这样做了,但是必须有一种方法可以有角度地做到这一点。
setHandleMaxPosition() {
const tempValues = this.fc.value;
tempValues[1] = this.values[this.indexOfNearestMax];
this.fc.setValue(tempValues);
this.handlePositions[1] = this.valuePositions[this.indexOfNearestMax];
var a = Array.from(document.getElementsByClassName('handle-slider__handle') as HTMLCollectionOf<HTMLElement>)
a[1].style.transform = "translate(" + this.valuePositions[this.indexOfNearestMin] + "px, 0px)";
}
解决方案
你确定你的value
变量包含一个数值吗?
因为[ngStyle]="{'transform': 'translate(' + value + 'px, 0px)'}"
我觉得好看。
推荐阅读
- typescript - 如何处理打字稿getter函数中的referenceError
- mysql - 数据库中的 MySQL 格式最多保留两位小数,其他时间为整数
- javascript - 如何在 AngularJS 中将毫秒转换为分钟
- database - MS Access - 基于另一列的列选择
- mingw - 无法刷esp32
- python - python 2.7 - 登录尝试
- c++ - CMake 在多个目标上构建后自定义命令?
- javascript - ASP.NET MVC 如何防止 jquery 加载两次?
- java - 为什么在检查字符串是否可以是双精度时出现错误
- sql - How safe is this generated query from SQL injection?