小编c0m*_*age的帖子

带有父子行的 Angular Material mat-table 的替代颜色

我有一个 Angular Material mat-table,我将 CSS 样式用于替代行颜色。这是 CSS 样式:

.mat-row:nth-child(even){
    background-color: #e4f0ec;
}

.mat-row:nth-child(odd){
    background-color:#ffffff;
}
Run Code Online (Sandbox Code Playgroud)

当我的 mat-table 没有定义子行时,这有效。当我添加另一个ng-container用“expandedDetail”指定的时,这不再起作用。所有行都是白色的,但展开的子行是彩色的。

我按照 material.angular.io 中的示例进行操作

我看到了行样式的其他示例,但他们使用 tr 标签。在示例和我的代码中,我ng-container为每一列使用了 an 、 th 和 td 标签。

任何帮助表示赞赏。

我将项目添加到 stackblitz

https://stackblitz.com/edit/angular-4bcxtv

这是我使用的 HTML 代码

<table mat-table
       [dataSource]="dataSource" multiTemplateDataRows
       class="mat-elevation-z8">
  <ng-container matColumnDef="{{column}}" *ngFor="let column of columnsToDisplay">
    <th mat-header-cell *matHeaderCellDef> {{column}} </th>
    <td mat-cell *matCellDef="let element"> {{element[column]}} </td>
  </ng-container>

  <!-- Expanded Content Column - The detail row is made up of this one column …
Run Code Online (Sandbox Code Playgroud)

css angular-material angular mat-table

5
推荐指数
2
解决办法
6905
查看次数

在 Angular 中应用条件类的最佳方法是什么?我应该使用 ngIf 或 ngClass 什么?

我有一个刷新图标,用于刷新或重新加载网格。但是使用以下代码

<i class="fas fa-sync fa-fw" (click)=refresh()></i>
Run Code Online (Sandbox Code Playgroud)

图标不动。我找到了以下旋转图标,但我只能找到有关如何减慢或加快旋转动画速度的文档。

<i class="fas fa-sync fa-spin" (click)=refresh()></i>
Run Code Online (Sandbox Code Playgroud)

我用谷歌搜索,发现只有npmjs一个可控的旋转图标,但不是我喜欢的。

我在想ngIfngClass。在它调用刷新功能重新加载数据的单击事件,是有办法的两个类之间切换fa-fwfa-spin。基本上,单击按钮时图标会旋转并在重新加载完成后停止?

对新手的任何帮助表示赞赏。谢谢。

angular

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

Angular 8 Firebase 获取 node_modules/firebase/index.d.ts(4369, 38): 错误 TS1005: ';' 预期的

我正在尝试让 firebase 在我的 Angular 8 应用程序上运行。

我删除了我的node_modules 运行 npm install 运行 npm install --save firebase @angular/fire 运行 npm run build

我收到以下错误

node_modules/firebase/nidex.d.ts(4396, 38) 中的错误:错误 TS1005:“;” 预期的

我尝试了其他帖子中的一些步骤,但尚未成功。任何帮助表示赞赏。

我的节点版本是v10.16.3

这是我的 package.json

   {
  "name": "material-dashboard-angular",
  "version": "2.1.0",
  "license": "MIT",
  "scripts": {
    "ng": "ng",
    "start": "ng serve",
    "build": "ng build",
    "test": "ng test",
    "lint": "ng lint",
    "e2e": "ng e2e"
  },
  "private": true,
  "dependencies": {
    "@agm/core": "1.0.0-beta.2",
    "@angular/animations": "5.2.9",
    "@angular/cdk": "5.2.4",
    "@angular/common": "5.2.9",
    "@angular/compiler": "5.2.9",
    "@angular/core": "5.2.9",
    "@angular/fire": "^5.2.1",
    "@angular/forms": "5.2.9",
    "@angular/http": "5.2.9",
    "@angular/material": …
Run Code Online (Sandbox Code Playgroud)

firebase angularfire angular

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

插值内的 Angular MatToolTip 条件

我正在为我的 MatToolTip 添加一个角度条件。起初,以下内容仅适用于 1 个字符串分配

matToolTip={{myData.name}}
Run Code Online (Sandbox Code Playgroud)

但我需要添加如下条件

matToolTip={{ myData.hasName : myData.name, myData.hasNoName : myData.NoNameMessage }}
Run Code Online (Sandbox Code Playgroud)

传入的数据有一个或另一个,而不是两者都有。

我发现了另一个 stackoverflow,它 ppl 说以下有效,但不在我的 Angular 7 代码中

{{element.source == 1 ? 'upwork' : (element.source == 2 ? 'refer from friend' : '')}}
Run Code Online (Sandbox Code Playgroud)

我尝试将它们放在单引号中,但没有成功。任何帮助是极大的赞赏。谢谢。

angular

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

如何将 Angular cli 运行到 https://localhost:4200 SSL 模式

我试图弄清楚如何配置我的 Angular CLI 环境以在 SSL HTTPS 模式下运行。

现在,它在常规的http://localhost:4200中运行,但无法访问运行 https 模式的 webAPI。我可以通过 google postman 从 webapi 获取数据,但不能使用我的 Angular 应用程序。

首先,我输入 mmc 并找到我的个人证书,显示为

本地主机 IIS Express 开发

我在 stackoverflow 上阅读了有关更改 json 文件中的设置的信息。我找不到 angular.json 文件。我在 cli 文件夹中找到了 package.json 但是当

如何设置我的角度应用程序以 https 模式运行以访问数据。

现在,它只是挂起。

谢谢。

ssl angular

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

.net core 3.1 如何添加HttpContext.Current和HttpContext.Current.Application[""]

我在这里读了一些帖子,似乎 System.Web 和 HttpContext.Current 已从 .net core 中删除。我在我的startup.cs中添加以下内容

services.addSingleton<IHttpContextAccessor, HttpContextAccesor>();

将 HttpContext.Current 添加到我的类中不起作用

在我的类库中,我将 Microsoft.AspNetCore.http 安装到我的依赖项中。我添加为 DI

public MyClass(IHttpContextAccessor _httpContextAccessor) {
  httpContextAccessor = _httpContextAccessor;
}
Run Code Online (Sandbox Code Playgroud)

在我的 cs 代码中,旧代码以

if(HttpContext.Current != null && HttpContext.Current.Application["Test"] != null]) 
Run Code Online (Sandbox Code Playgroud)

替代品是什么,到目前为止还不起作用

httpContextAccessor.HttpContext.Session != null 

Not sure what is the equivalent to HttpContext.Current.Application["Test"]
Run Code Online (Sandbox Code Playgroud)

谢谢

asp.net asp.net-core

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

Angular Material Mat-Card 插值添加 html 格式字符串错误

我有一个 Angular Material Mat-Card,我需要添加插值以将内容字符串添加到 mat-card-content。

以下作品无需插值

 <mat-card-content>
            <p>Guidelines.</p>
            <p>Click on the folliwng link for additional information</p>
            <a href="http://mySite/documents/guidances.docx">http://mySite/documents/guidances.docx</a>
        </mat-card-content>
Run Code Online (Sandbox Code Playgroud)

带有工作链接的渲染页面

我的内容将来自网络服务,不再是静态页面。现在我插入内容如下

<mat-card>
                        **<mat-card-content>{{message.content}}</mat-card-content>**
                    </mat-card>
Run Code Online (Sandbox Code Playgroud)

当 hmtl 页面呈现时,它不会对字符串进行任何 html 格式化。

看起来像这样

<p>Guidelines.</p><p>UClick on the folliwng link for additional information</p><a href="http://mySite/documents/guidances.docx">http://mySite/documents/guidances.docx</a>
Run Code Online (Sandbox Code Playgroud)

它只是将 html 代码粘贴到 amt-card 中。

任何帮助表示赞赏。谢谢

angular-material angular

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

Angular Typescript无法从keyvalue对中获取键值

几个月我添加了一系列keyvalue.

  months : { [key: number]: string } = { 1: 'January', 2: 'February', 3: 'March', 
  4: 'April', 5: 'May', 6: 'June', 7: 'July', 8: 'August', 9: 'September', 10: 'October',
  11: 'November', 12: 'December' } 
Run Code Online (Sandbox Code Playgroud)

我可以毫无问题地获得价值

var firstMonth = this.months [0] .valueOf();

但是,我无法获得关键价值.

我试过了.months [0] .key.这不起作用

当我使用var firstMonth = this.months [0]时,我只看到'January'的值.访问数组中的一个元素时,我没有看到keyvalue.当我将鼠标悬停在数组上时,我会看到所有月份都包含两个键值.

我看到在stackblitz中使用*ngFor for angular6-keyvaluepipe-demo的示例,但我无法访问typescript文件中的键值.

任何帮助表示赞赏.

key-value typescript angular

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

单元测试 无法跟踪实体类型的实例,因为已跟踪具有相同 {'Id'} 键值的另一个实例

我正在编写一个 webAPI 单元测试,其中对类中的每个方法都有多个测试调用。我正在使用 UseInMemoryDatabase 创建数据库并加载测试数据。

我在每种测试方法之间遇到以下错误

无法跟踪实体类型“AppSettings”的实例,因为已跟踪具有相同键值 {'myId '} 的另一个实例。附加现有实体时,确保仅附加一个具有给定键值的实体实例

我添加了 context.Database.EnsureDeleted(); 这消除了 Get 方法的错误,但它仍然在删除和更新单元测试中引发错误。

当我一次运行所有测试方法时,我不知道如何消除删除和更新时的此错误。

任何帮助表示赞赏。

        private MyDBContext context;

        [TestInitialize]
        public void SetUp()
            {
            var options = new DbContextOptionsBuilder<MyDBContext>()
                .UseInMemoryDatabase(databaseName: "MyDB")
                .Options;

            context = new CACIDBContext(options);
 
            context.Database.EnsureDeleted();  // this removed the error between the several GET test methods. but not the delete,update
            context.AppSettings.Add(new AppSettings { myId = 1, MyName = "test1", MyValue = "test1" });
            context.AppSettings.Add(new AppSettings { myId = 2, MyName = "test2", MyValue = "test2" });
            context.AppSettings.Add(new …
Run Code Online (Sandbox Code Playgroud)

unit-testing moq visual-studio

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