小编Gau*_*rda的帖子

为什么当数组元素相同时 Splice 仅删除最后一个元素

转到此StackBlitz 链接( Not Working)

转到此StackBlitz 链接( Working Fine)

我的问题是关于Array.splice. 当数组数据不同时,Array.splice 工作正常,但当数组数据相同时,Array.splice仅删除最后一个索引。在这种情况下,splice 会忽略提供的索引以从数组中删除元素。

这两个示例都有通用的 HTML 模板

<div class="container">
    <table class="table table-dark table-striped table-hover">
        <thead>
           <tr>
               <td scope="col"> Index </td>
               <td scope="col"> Value </td>
               <td scope="col"> Action </td>
           </tr>
        </thead>
        <tbody>
            <tr *ngFor="let row of rows; let i = index"  [@itemAnim]>
                <td> {{i}} </td>
                <td>{{row}}</td>
                <td><button class="btn btn-danger" (click)="deleteRow(i)">Delete</button></td>
           </tr>
        </tbody>
    </table>
    <button class="btn btn-primary " (click)="addRow()">Add row</button>
</div>
Run Code Online (Sandbox Code Playgroud)

请参阅此示例按预期工作

index …
Run Code Online (Sandbox Code Playgroud)

javascript typescript angular

3
推荐指数
1
解决办法
3900
查看次数

Best way to access CSS Variable in custom Directive of angular

I have one question about.. How can we convert below statement to angular`s renderer2 ?

this.elementRef.nativeElement.style.setProperty( '--primary-color ' , '#455363' )
Run Code Online (Sandbox Code Playgroud)

Above statement is changing css-variable into the directive when dark mode is selected. As in angular it is not good practice to access DOM directly, thats why we uses renderer2. But i do not know how to convert above statement to renderer2 for safely access DOM.

At very simple, can anyone tell me how to safely change css-varible in …

javascript css typescript angular

1
推荐指数
1
解决办法
953
查看次数

标签 统计

angular ×2

javascript ×2

typescript ×2

css ×1