GVKun编程网logo

angularjs – Angular-Material – 带主题的Bug(angular样式)

19

在本文中,我们将给您介绍关于angularjs–Angular-Material–带主题的Bug的详细内容,并且为您解答angular样式的相关问题,此外,我们还将为您提供关于Angular-如何验证

在本文中,我们将给您介绍关于angularjs – Angular-Material – 带主题的Bug的详细内容,并且为您解答angular样式的相关问题,此外,我们还将为您提供关于Angular - 如何验证 Angular Material stepper 中的每一步、Angular 9-Angular Material垫分页器不起作用、Angular w / Angular Material – 对话主题被打破、Angular 表排序,无 Angular Material的知识。

本文目录一览:

angularjs – Angular-Material – 带主题的Bug(angular样式)

angularjs – Angular-Material – 带主题的Bug(angular样式)

我最近偶然发现了 Angular-Material.但是看起来主题文件并没有被基本的angular-material.css文件自动包含.

因此,我必须手动包含我想要使用的每个颜色主题…

如果有人有这方面的经验你知道这是一个错误还是这个故意.

这是我正在使用的代码的链接.运行页面时,不会加载所有应用于非默认主题的md-theme的进度循环项.位于angular-material / themes /的CSS文件未自动加载.

HTML Gist

解决方法

这是故意的. Angular-Material意味着模块化,旨在允许开发人员尽可能多地控制他们愿意投入应用程序的数据传输量.颜色主题是众多可选组件之一.

从using themes开始:

To use other themes and override parts [or all] of the default theme,you must include those extra theme stylesheets.

Angular - 如何验证 Angular Material stepper 中的每一步

Angular - 如何验证 Angular Material stepper 中的每一步

如何解决Angular - 如何验证 Angular Material stepper 中的每一步?

在 Angular-12 中,我正在实施 Material Stepper。它有两 (2) 个步骤:

组件:

export class SignupCompanyComponent implements OnInit {
  isLinear = true;
  isLoading = false;
  companySetupForm!: FormGroup;
  companyForm!: FormGroup;
  idForm!: FormGroup;

  ngOnInit() {
    this.companyForm = this.fb.group({
      companyName: ['''',[Validators.required,Validators.minLength(3),Validators.maxLength(100)]]
    });
    this.idForm = this.fb.group({
      registrationNumber: ['''',Validators.maxLength(100)]],});
  }

  get fc() {
    return this.companyForm.controls;
  };
  get fi() {
    return this.idForm.controls;
  };

  onSubmit() {}
}

HTML:

<mat-horizontal-stepper [linear]="isLinear" #stepper labelPosition="bottom">
  <mat-step [stepControl]="companyForm">
    <form [formGroup]="companyForm">
      <ng-template matStepLabel matStepperIcon="phone">Company Info</ng-template>

      <div>
        <div>
          <label for="name">Company Name:<span>*</span></label>}
          <input type="text" formControlName="companyName" placeholder="Company Name"required/>
        </div>
        <div *ngIf="fc.companyName.touched && fc.companyName.invalid">
          <div *ngIf="fc.companyName.hasError(''required'')">
            <div>
              Company Name is required!
            </div>
          </div>
          <div *ngIf="fc.companyName.hasError(''minlength'')">
            <div>
              Company Name cannot be less than 3 characters!
            </div>
          </div>
          <div *ngIf="fc.companyName.hasError(''maxlength'')">
            <div>
              Company Name cannot be more than 100 characters!
            </div>
          </div>
        </div>
      </div>
      <div>
        <button mat-raised-button color="primary" matStepperNext>Next</button>
      </div>
    </form>
  </mat-step>
  <mat-step [stepControl]="idForm">
    <form [formGroup]="idForm">
      <ng-template matStepLabel>Company ID</ng-template>
      <div>
        <div>
          <label for="registration_number">Registration Number:<span>*</span></label>
          <input type="text" formControlName="registrationNumber" placeholder="Registration Number"required/>
        </div>
        <div *ngIf="fi.registrationNumber.touched && fi.registrationNumber.invalid">
          <div *ngIf="fi.registrationNumber.hasError(''required'')">
            <div>
              Company Reg. No. is required!
            </div>
          </div>
          <div *ngIf="fi.registrationNumber.hasError(''maxlength'')">
            <div>
              Company Reg. No. cannot be more than 100 characters!
            </div>
          </div>
        </div>
      </div>
      <div>
        <button mat-raised-button color="black" matStepperPrevIoUs>Back</button> &nbsp;
        <button mat-raised-button color="success" [disabled]="isLoading" type="submit" (click)="onSubmit()">
                <span *ngIf="isLoading"></span>
                  Submit
              </button> &nbsp;
        <button mat-raised-button color="warn" (click)="stepper.reset()">Reset</button>
      </div>
  </mat-step>
</mat-horizontal-stepper>

当每个 formControl 被触摸时,Material Stepper 工作正常。它立即显示错误。 但是当点击Next Button时,Step1(companyForm)中没有填写数据,虽然没有移动到下一步或表单,但没有显示错误。

我希望它验证每个步骤并在触摸每个表单控件时显示它。

我如何实现这一目标?

谢谢

解决方法

材料似乎没有将表单标记为已触摸,所以我会重新绑定按钮:

<button mat-raised-button color="primary" (click)="onFirstStepDone()">Next</button>

在组件中,您需要对步进器的引用:

@ViewChild(''stepper'') stepper: MatHorizontalStepper;

onFirstStepDone() {
   if(!this.companyForm .valid) {
       // this should make all invalid fields light up in red
       this.companyForm.markAllAsTouched();
       return;
   }
   this.stepper.next();
}
,

我做的两件事是将字段验证设置为 onBlur like;

this.companyForm = this.fb.group({
      companyName: ['''',[Validators.required,Validators.minLength(3),Validators.maxLength(100)]]
    },{ updateOn: "blur" });

...我个人不喜欢在必填字段有效之前允许继续,所以我将步进器按钮设置为禁用,直到它像;

<button mat-raised-button
        color="primary"
        matStepperNext
        [disabled]="companyForm.status != ''VALID''">
   Next
</button>

或者一定要看看下面曼哈顿先生的评论来验证最后的表格,你可以通过将上面的 { updateOn: "blur" }blur 更改为 submit 来完成同样的事情

Angular 9-Angular Material垫分页器不起作用

Angular 9-Angular Material垫分页器不起作用

我通过更新角度/材质解决了该问题。另外,我已经改变了

import { MatTableDataSource } from '@angular/material';

 import { MatTableDataSource } from '@angular/material/table';

它解决了我的问题。希望对其他人有帮助。

Angular w / Angular Material – 对话主题被打破

Angular w / Angular Material – 对话主题被打破

您好我在对话框组件中遇到Angular Material主题的问题,其中文本和其他组件的颜色不按照应有的方式工作.

在app.component中我有一个设置图标按钮,用于打开一个对话框main.settings.dialog但是当它打开时,如下图所示,着色不适合黑暗主题.

任何关于为什么这不能以正常方式工作的见解将非常感激,因为我找不到解决这个问题的方法.

Live example site

Link to full source code

enter image description here

解决方法

由于您在样式类中包含主题,因此需要将其添加到全局覆盖容器中.

以下是您的AppModule中的方法:

import {OverlayContainer} from '@angular/cdk/overlay';

@NgModule({
      // ...
})
export class AppModule {
      constructor(overlayContainer: OverlayContainer) {
          overlayContainer.getContainerElement().classList.add('app-dark-theme');
      }
}

链接到官方文档:https://material.angular.io/guide/theming#multiple-themes

Angular 表排序,无 Angular Material

Angular 表排序,无 Angular Material

如何解决Angular 表排序,无 Angular Material?

我想在我的表格中搜索,但我希望表格一开始就填满我的数据。 目前,它只会在我开始在搜索栏中输入时填充。

我认为问题出在组件初始化时productsArray为空

我的数据来自项目中的 JSON 文件。

下面你可以看到我目前拥有的

export class TableComponent implements OnInit {
      searchText: any;
      productsArray: Products[] = [];
      filteredArray = [...this.productsArray];

      constructor(private http: HttpClient) {}

      ngOnInit(): void {
        this.getProducts().subscribe((res) => {
          this.productsArray = res;
        });
      }
      getProducts(): Observable < Products[] > {
        return this.http
          .get < any > (''assets/mock.data.json'')
          .pipe(map((results) => results.data));
      }
      filterarray(): any {
        if (!this.productsArray.length) {
          this.filteredArray = [];
          return;
        }

        if (!this.searchText) {
          this.filteredArray = [...this.productsArray];
          return;
        }

        const products = [...this.productsArray];
        const properties = Object.keys(products[0]);

        this.filteredArray = products.filter((product) => {
          return properties.find((property) => {
              const valueString = product[property].toString().toLowerCase();
              return valueString.includes(this.searchText.toLowerCase());
            }) ?
            product :
            null;
        });
      }
    }
代码 名称 类别
<tbody *ngFor="let product of filteredArray; let i = index">
  <tr>
    <td>{{ product.code }}</td>
    <td>{{ product.name }}</td>
    <td>{{ product.category }}</td>
  </tr>
</tbody>

解决方法

filteredArray 被初始化时,它是空的。只有在调用 filteredArray 时,filterArray() 才会填充一些值。所以在 ngOnInit() 中提供 filteredArray 的值。 试试这个:

ngOnInit(): void {
    this.getProducts().subscribe((res) => {
      this.productsArray = res;
      this.filteredArray = [...this.productsArray];
    });
  }
,

你需要使用管道,有些像这样

@Pipe({
    name: ''filterPipe''
})
export class FilterPiper implements PipeTransform {
    transform(array: any[],properties: any[],filter: string) {
        if (!array) {
            return [];
        }
        if (!properties.length || !filter) {
            return array;
        }

        filter = filter.trim().toLowerCase();
        return array.filter((element) => 
      !!(properties.find((property) => {
          const valueString = product[property].toString().toLowerCase();
          return valueString.includes(filter)
        )) 
    });
}

在 html 中

 <tbody *ngFor="let product of productsArray | filterPipe: propertiesArray : searchText ; let i = index">
  <tr>
    <td>{{ product.code }}</td>
    <td>{{ product.name }}</td>
    <td>{{ product.category }}</td>
  </tr>
</tbody>

记住管道需要在模块中声明并导入到你的组件中

今天关于angularjs – Angular-Material – 带主题的Bugangular样式的讲解已经结束,谢谢您的阅读,如果想了解更多关于Angular - 如何验证 Angular Material stepper 中的每一步、Angular 9-Angular Material垫分页器不起作用、Angular w / Angular Material – 对话主题被打破、Angular 表排序,无 Angular Material的相关知识,请在本站搜索。

本文标签:

上一篇AngularJS指令前缀会影响HTML编译的速度吗?(angularjs指令的作用)

下一篇angularjs – 如何将cordova添加到现有的角度项目中(angular引入外部js文件)