小编zac*_*cko的帖子

StructureMap:创建为瞬态(根据请求)不起作用

我正在尝试解决 IoC 问题,一开始看起来很简单,但结果却很痛苦:-P

我有一个重量级主类,它必须只初始化一次,因此它被标记为单例。然而,该类使用一个必须为每个请求创建一次的子类,因此它被标记为 Transient:

public class MyRegistry : Registry
{
    public MyRegistry()
    {
        For<IMainClass>()
            .Singleton()
            .Use(ctx => new MainClass(() => ctx.GetInstance<ISubClass>()));

        For<ISubClass>()
            .Transient()
            .Use(ctx => CreateNewInstanceOfSubClass());
    }

    private ISubClass CreateNewInstanceOfSubClass()
    {
        return new SubClass();
    }
}

public interface ISubClass
{ }

public class SubClass : ISubClass
{ }

public interface IMainClass
{ }

public class MainClass : IMainClass
{
    private readonly Func<ISubClass> _subClassProvider;

    public MainClass(Func<ISubClass> subClassProvider)
    {
        _subClassProvider = subClassProvider;
    }

    public void DoStuff()
    {
        var requestSpecificInstanceOfSubClass = _subClassProvider(); …
Run Code Online (Sandbox Code Playgroud)

c# structuremap dependency-injection ioc-container

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

How to create a horizontally oriented table with Angular Material (mat-table

I'm using angular material 8.2.3 for my site. But currently I'm stuck with a seemingly easy problem. I want to order a table horizontally instead of vertically.

My table consists of only two columns. Here's the code:

<table mat-table [dataSource]="items" class="mat-elevation-z8 table-hover">

  <ng-container matColumnDef="percent">
    <th mat-header-cell *matHeaderCellDef> %</th>
    <td mat-cell *matCellDef="let items">{{items.percent}}</td>
  </ng-container>

  <ng-container matColumnDef="value">
    <th mat-header-cell *matHeaderCellDef> val. </th>
    <td mat-cell *matCellDef="let items">{{items.value}}</td>
  </ng-container>

  <tr mat-header-row *matHeaderRowDef="displayedColumns"></tr>
  <tr mat-row *matRowDef="let row; columns: displayedColumns;"></tr>

</table>
Run Code Online (Sandbox Code Playgroud)

The resulting table looks like …

angular-material angular

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

已检查的角度材料滑动切换绑定不起作用

这似乎很容易,但我就是无法让checked滑动切换的绑定工作。

(我正在使用 Angular9.1和 Material 9.2。)

这是 HTML:

<mat-slide-toggle [checked]="isSlideChecked" (change)="toggleChanges($event)">isSlideChecked: {{isSlideChecked}}</mat-slide-toggle>

<p *ngFor="let e of toggleEvents">{{e}}</p>
Run Code Online (Sandbox Code Playgroud)

这是 TS:

import { Component, OnInit } from '@angular/core';
import { MatSlideToggleChange } from '@angular/material/slide-toggle';

@Component({
  selector: 'app-test-component',
  templateUrl: './test-component.component.html',
  styleUrls: ['./test-component.component.scss']
})
export class TestComponentComponent implements OnInit {

  public isSlideChecked: boolean = false;
  public toggleEvents: string[] = [];

  constructor() { }

  ngOnInit(): void {
  }

  toggleChanges($event: MatSlideToggleChange) {
    this.toggleEvents.push("Toggle Event: " + $event.checked)
  }
}
Run Code Online (Sandbox Code Playgroud)

change事件工作正常, …

angular-material angular angular9

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

排序后材料表上的可扩展行不起作用

根据Angular Material Table中的示例,我向表中添加了可扩展行和排序。每个功能都具有独特的魅力。但是,当我在表格排序后尝试展开一行时,第一次单击似乎根本没有执行任何操作。第二次单击打开该行并立即再次关闭它。当我再次单击同一行时,它再次表现正常。

这是 stackblitz 上的简化版本:https ://stackblitz.com/edit/angular-mnqztk

据我通过日志记录发现,expandedElement无论表是否已排序,每次单击的属性都会正确设置。所以我猜动画触发器有问题detailExpand。我只是无法弄清楚为什么它在expandedElement表格排序后设置时没有被触发。

angular-material angular

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