标签: angular6

我想使用反应形式和角度材料一次显示一个错误

我正在使用 Angular 反应形式和 Angular 材料。我的代码运行良好。但我想一次显示一个错误

我的 .html 文件代码

      <form [formGroup]="accountDetailsForm" novalidate (ngSubmit)="onSubmitAccountDetails(accountDetailsForm.value)">

        <mat-form-field class="full-width">
          <input matInput maxlength="25" placeholder="Username" formControlName="username" required>
          <mat-error *ngFor="let validation of account_validation_messages.username">
            <mat-error class="error-message" *ngIf="accountDetailsForm.get('username').hasError(validation.type) && (accountDetailsForm.get('username').dirty || accountDetailsForm.get('username').touched)">{{validation.message}}</mat-error>
          </mat-error>
        </mat-form-field>

        <mat-form-field class="full-width">
          <input matInput type="email" placeholder="Email" formControlName="email" required>
          <mat-error *ngFor="let validation of account_validation_messages.email">
            <mat-error class="error-message" *ngIf="accountDetailsForm.get('email').hasError(validation.type) && (accountDetailsForm.get('email').dirty || accountDetailsForm.get('email').touched)">{{validation.message}}</mat-error>
          </mat-error>
        </mat-form-field>


        <div formGroupName="matching_passwords">
          <mat-form-field class="full-width">
            <input matInput type="password" placeholder="Password" formControlName="password" required>
            <mat-error *ngFor="let validation of account_validation_messages.password">
              <mat-error class="error-message" *ngIf="accountDetailsForm.get('matching_passwords').get('password').hasError(validation.type) && (accountDetailsForm.get('matching_passwords').get('password').dirty || accountDetailsForm.get('matching_passwords').get('password').touched)">{{validation.message}}</mat-error>
            </mat-error>
          </mat-form-field> …
Run Code Online (Sandbox Code Playgroud)

mean angular-material angular angular-reactive-forms angular6

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

如何设置 mat-grid-tile 的宽度

超文本标记语言

 <mat-grid-list cols="2" [cols]="breakpoint" rowHeight="486px" (window:resize)="onResize($event)">
   <mat-grid-tile >

   </mat-grid-tile>
   <mat-grid-tile >

   </mat-grid-tile>
</mat-grid-list>
Run Code Online (Sandbox Code Playgroud)

我如何为第一个设备提供 30% 的宽度,为mat-grid-tile第二个设备提供 70% 的宽度,以及如何为所有设备mat-grid-tile设置等效高度?mat-grid-tile

angular-material angular angular6

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

为什么我在 Angular 6 中的服务出现错误?

我有一个服务:

import { EventEmitter, Injectable } from '@angular/core';

@Injectable()
export class PingOnActionListenerService {
    removingListener = new EventEmitter();

    removeListener(): void {
        this.removingListener.emit();
    }
Run Code Online (Sandbox Code Playgroud)

在组件 AI 处调用服务:

this._pingOnActionListenerService.removeListener();
Run Code Online (Sandbox Code Playgroud)

在组件BI想要监听服务:

    ngOnInit() {
        this._pingOnActionListenerService.removingListener.subscribe(this.deactivatelistener());
    }

    deactivatelistener() {
        window.removeEventListener('click', this.pingIfLastPingIsOld);
    }
Run Code Online (Sandbox Code Playgroud)

当我运行此代码时,我在控制台上收到错误消息:

core.js:1671 错误 TypeError:generatorOrNext 不是 SafeSubscriber.schedulerFn [as _next] (core.js:3565) 的函数,位于 SafeSubscriber.push../node_modules/rxjs/_esm5/internal/Subscriber.js.SafeSubscriber.__tryOrUnsub (Subscriber.js:195) 在 SafeSubscriber.push../node_modules/rxjs/_esm5/internal/Subscriber.js.SafeSubscriber.next (Subscriber.js:133) 在 Subscriber.push../node_modules/rxjs/_esm5/internal /Subscriber.js.Subscriber._next (Subscriber.js:77) 在 Subscriber.push../node_modules/rxjs/_esm5/internal/Subscriber.js.Subscriber.next (Subscriber.js:54) 在 EventEmitter.push.. /node_modules/rxjs/_esm5/internal/Subject.js.Subject.next (Subject.js:47) 在 EventEmitter.push../node_modules/@angular/core/fesm5/core.js.EventEmitter.emit (core.js :3537) 在PingOnActionListenerService.push../src/app/core/services/ping-on-action/ping-on-action-listener.service.ts.PingOnActionListenerService.removeListener (ping-on-action-listener.service. ts:19) 在 CatchSubscriber.selector (logging-interceptor.ts:45) 在 CatchSubscriber.push../node_modules/rxjs/_esm5/internal/operators/catchError.js.CatchSubscriber.error (catchError.js:33)

angular angular6

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

Angular 材质 6 的环绕菜单组件

我正在包装角度材质菜单组件。我正在扩展 MatMenuTrigger、MatMenuItem,将它们作为单独的指令并在父组件中使用它。在子组件(菜单组件)中,我仅使用 mat-menu 来获取引用,在父组件(菜单演示组件)中,将菜单(位于子组件中)附加到我们想要的任何控件。我不应该在子组件内使用按钮标签,所以我使用 ng-content 从父组件获取内容。我只想公开一些属性来获取该引用。我的问题是如何包装这个参考菜单stackblitzlink。请帮我解决这个问题,提前致谢。

typescript angular-directive angular6 angular-material-6

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

Angular 6 htttp POST - 将参数设置为 URL 中的查询字符串

我有一个基于 asp .net core 样板的应用程序。我需要从我的 Angular 6 应用程序发送 http POST 参数。

我的服务如下所示:

public findProduct(productCode: string) {
const url_ = 'api/product/findProduct';
const params = new URLSearchParams();
params.set('productCode', productCode);

return this.http.post(url_, params, httpHeaders)
  .subscribe(
    result => {
      console.log(result);
    },
    error => {
      console.log('There was an error: ')
    }
  );
Run Code Online (Sandbox Code Playgroud)

我已经从 @angular/http 导入了 URLSearchParams,但仍然遇到同样的问题。我的 POST URL 很糟糕,因为 API 期望 POST URL 如下所示: http://localhost:21021/api/product/findProduct?productCode=1111并查询字符串参数,如: productCode: 1111

但我的看起来像这样: http://localhost:21021/api/product/findProduct 并设置请求负载(始终为空):

**{rawParams: "", queryEncoder: {}, paramsMap: {}}
paramsMap: {}
queryEncoder: {}
rawParams: ""**
Run Code Online (Sandbox Code Playgroud)

我的 httpHeaders …

http-post angular angular6

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

隐藏指定路线上的标头 - 角度 6

我试图隐藏标题,仅在一条路线中。

假设我有 3 条路线route1、route2和route3。

我有一个名为 的组件app-header。

app-header我希望当用户输入时隐藏该组件route1,并在其他 2 个路由中显示该组件。

我在 stackoverflow 上找到了一些主题,但没有一个对我有帮助=/

你们能给我一些帮助吗?

这是我的代码:

  • 应用程序组件.ts

    export class AppComponent implements OnInit {
        showHeader = true;
    
        constructor(
            private router: Router
        ) {
            this.router.events.subscribe(event => this.modifyHeader(event));
        }
    
        ngOnInit() {
        }
    
        modifyHeader(location) { // This method is called many times
            console.log(location.url); // This prints a loot of routes on console
            if (location.url === '/route1') {
                this.showHeader = false;
            } else {
                this.showHeader = …
    Run Code Online (Sandbox Code Playgroud)

typescript angular angular6

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

非法状态:无法加载指令 AppComponent 的摘要

我正在用 Angular 编写一个 spec.ts 文件并收到以下错误:

失败:非法状态:无法加载指令 AppComponent 的摘要。

下面是我尝试过的代码

import { TestBed, async } from "@angular/core/testing";
    import { AppComponent } from "./app.component";

    describe('AppComponent', () => {
        beforeEach(() => {
            TestBed.configureTestingModule({
                declarations: [
                    AppComponent
                ],
            });
        });
    });

    it('should create the app', async(() => {
        let fixture = TestBed.createComponent(AppComponent);
        let app = fixture.debugElement.componentInstance;
        expect(app).toBeTruthy();
    }));``
Run Code Online (Sandbox Code Playgroud)

angular6

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

在 ngx-datatable 中显示带有列名称的图标

我在 Angular 6 项目中使用ngx-datatable,我需要显示一个带有列名称的图标,如下面的屏幕截图所示。(在我需要显示图标的地方标记为x )

在此输入图像描述

这是我当前的数据表代码。

<ngx-datatable
   *ngIf="!isDataLoading"
   class="data-table"
   [scrollbarH]="true"
   [rows]="rowsData"
   [columnMode]="'force'"
   [columns]="columnsData"
   [headerHeight]="50"
   [footerHeight]="50"
   [rowHeight]="'auto'"
   [limit]="10"
   [selected]="selected"
   [selectionType]="'single'"
   (select)='onSelect($event)'>
</ngx-datatable>
Run Code Online (Sandbox Code Playgroud)

在 mypage.component.ts 中

columnsData = [
   { prop: 'dataName', name: 'Name' },
   { prop: 'dataGender', name: 'Gender' },
   { prop: 'dataCompany', name: 'Company' }
];
Run Code Online (Sandbox Code Playgroud)

如何显示带有列名称的图标?

ngx-datatable angular angular6

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

将鼠标悬停在某个项目上以显示特定于该项目的 div

我用来*ngFor循环并显示deals数组中的项目

   <div class="card item" *ngFor="let deal of deals; let i = index">
      <div class="card-body item-body">...</div>
    </div>
Run Code Online (Sandbox Code Playgroud)

我想要实现的是,当我将鼠标悬停card在html中的div时,card-body将显示他相应的div。使用 jquery 是一项相当简单的任务,但使用 Angular 却无法做到这一点。

我正在寻找解决方案,但没有成功实现它。实现这一目标的方法是什么?

typescript angular angular6

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

Angular 6路由器链接问题在同一页面

我有两个链接:

  1. ['/productlist',1000]
  2. ['/productlist',1001]

这两个链接位于同一页面上。如果我第一次点击任何链接。它正在重定向到该页面,但如果我单击其他链接,它就不起作用。

组件.html代码

<a class="dropdown-item" (click)="GetProductList(subitem.SubCategoryID)">
 <i class="mdi mdi-chevron-right" aria-hidden="true"></i> 
 {{ subitem.SubCategoryName}}
</a> 

GetProductList(SubCategoryID){ 
    this.router.navigate(['/productlist',SubCategoryID]); 
}
Run Code Online (Sandbox Code Playgroud)

angular-components angular angular6

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