小编Roy*_*Roy的帖子

如何以及何时使用'async'和'await'

从我的理解主要事情之一asyncawait要做的就是让代码易于读写-但使用它们等于产卵后台线程来执行持续时间长的逻辑?

我正在尝试最基本的例子.我在内联添加了一些评论.你能为我澄清一下吗?

// I don't understand why this method must be marked as `async`.
private async void button1_Click(object sender, EventArgs e)
{
    Task<int> access = DoSomethingAsync();
    // task independent stuff here

    // this line is reached after the 5 seconds sleep from 
    // DoSomethingAsync() method. Shouldn't it be reached immediately? 
    int a = 1; 

    // from my understanding the waiting should be done here.
    int x = await access; 
}

async Task<int> DoSomethingAsync()
{
    // is …
Run Code Online (Sandbox Code Playgroud)

.net c# asynchronous async-await

989
推荐指数
19
解决办法
78万
查看次数

如何在Angular 4中翻译mat-paginator?

您有什么想法我如何翻译Angular mat-paginator标签中的"每页项目数" ?这mat-paginator是Material Design的一个元素.

material-design angular-material angular

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

outerHeight(true)给出错误的值

我想要一个容器元素的高度,包括边距和填充.

当我将鼠标悬停在Chrome开发工具中的元素上时,我获得了我正在寻找的值,但是当我使用jQuery时$('element').outerHeight(true); 我得到的价值要小得多.

该元素包含一个jQuery轮播(在带有position:relative项目的容器中position: absolute),可能与它有关吗?

提前致谢

jquery positioning dimensions

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

如何在 Angular 中使用 DecimalPipe 向上或向下舍入数字

我认为如何DecimalPipe在 Angular 中使用向上或向下舍入一个数字,默认情况下会舍入一个数字,例如:
DecimalPipe

 Rounding({{value | number:'1.0-2'}})
 1.234 => 1.23
 1.235 => 1.24
Run Code Online (Sandbox Code Playgroud)

就我而言,我想向上/向下舍入一个数字,例如:

 Rounding up({{value | number:'1.0-2'}})
 1.234 => 1.24
 1.235 => 1.24

 Rounding down({{value | number:'1.0-2'}})
 1.234 => 1.23
 1.235 => 1.23
Run Code Online (Sandbox Code Playgroud)

我怎样才能直接使用DecimalPipe

typescript angular

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

如何更改Angular Material2中主要调色板的字体颜色?

Angular Material2的官方主题文档中,它清楚地说明了以下内容:

在Angular Material中,通过组合多个调色板来创建主题.特别是,主题包括:

  • 主要调色板:在所有屏幕和组件中使用最广泛的颜色.
  • 重点调色板:用于浮动操作按钮和交互元素的颜色.
  • 警告调色板:用于传达错误状态的颜色.
  • 前景调色板:文本和图标的颜色.
  • 背景调色板:用于元素背景的颜色.

但在每个例子中,他们只修改前三个:

@import '~@angular/material/theming';
@include mat-core();

$candy-app-primary: mat-palette($mat-indigo);
$candy-app-accent:  mat-palette($mat-pink, A200, A100, A400);
$candy-app-warn:    mat-palette($mat-red);
$candy-app-theme: mat-light-theme($candy-app-primary, $candy-app-accent, $candy-app-warn);

@include angular-material-theme($candy-app-theme);
Run Code Online (Sandbox Code Playgroud)

所以我的问题是:如何更改前景调色板以更改主调色板或辅助调色板的文本颜色?

有一些网站(materialpalette.com,material.io)显示了易于可视化的调色板,但他们仍未说明如何在Angular Material2中包含或修改该调色板.

css fonts textcolor angular-material2

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

如何更改垫子分隔线的颜色?

是否可以改变mat-divider颜色?我尝试了以下方法,没有用

组件.html

<mat-divider class="material-devider"></mat-divider>
Run Code Online (Sandbox Code Playgroud)

组件.scss

.material-devider {
    color: red
}
Run Code Online (Sandbox Code Playgroud)

html css sass angular-material angular

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

使 Material Tooltip 中的部分文本加粗

所以,假设我有一个mat-tooltip这样的元素:

<button mat-raised-button matTooltip="Info about the action">
  Action
</button>
Run Code Online (Sandbox Code Playgroud)

现在,如何仅将文本的“信息”部分设为粗体?我正在考虑使用:before伪元素,但我的情况下的工具提示内容是动态呈现的。你对如何实现它有什么想法吗?

sass angular-material angular

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

覆盖外部组件的封装CSS

我想知道如何覆盖外部组件的封装CSS.

所以我在我的项目中使用material2,而tabs组件有一个属性溢出设置tab-body.是否可以覆盖溢出值?

css angular-material angular

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

在Angular反应形式中使用updateOn:'blur'

我只想在用户离开字段(onblur)时才开始验证表单的字段。

我正在尝试以这种方式:

    this.profileForm = this.fb.group({
                firstName: ['initial value',
                    [Validators.required, Validators.minLength(2), forbiddenNameValidator(/bob/i)],
                    [forbiddenNameValidatorAsync()],
                    { updateOn: 'blur' }
                ],
                lastName: ['b']
            });

Run Code Online (Sandbox Code Playgroud)

但是这种方式是行不通的。验证(同步和异步)在onChange期间执行。

我也想问一下如何通过对进行检查来验证名称lastName

示例:如果名称字段与姓氏相同(仅名称字段,而不是整个表单,而不是两个字段),则希望禁用该名称字段。

angular

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

Nullinjectorerror:没有 httpclient 的提供者!没有 app.module.ts

我正在尝试使用 HttpClient 读取 Ionic Angular 中的 JSON,但收到此错误“nullinjectorerror:没有 httpclient 的提供程序!”。

问题是最新版本的 Angular 不会生成 app.module.ts。

我的代码:

import { Component, OnInit } from '@angular/core';
import { CommonModule } from '@angular/common';
import { FormsModule } from '@angular/forms';
import { IonicModule } from '@ionic/angular';

import { HttpClient } from '@angular/common/http';
import { map } from 'rxjs';

@Component({
  selector: 'app-ficha-evento',
  templateUrl: './ficha-evento.page.html',
  styleUrls: ['./ficha-evento.page.scss'],
  standalone: true,
  imports: [IonicModule, CommonModule, FormsModule]
})
export class FichaEventoPage implements OnInit {

  event:any=[];

  constructor(private http: HttpClient) { }

  ngOnInit() {
    this.getEvnt().subscribe(res=>{ …
Run Code Online (Sandbox Code Playgroud)

httpclient ionic-framework angular ionic6

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