RError.com

RError.com Logo RError.com Logo

RError.com Navigation

  • 主页

Mobile menu

Close
  • 主页
  • 系统&网络
    • 热门问题
    • 最新问题
    • 标签
  • Ubuntu
    • 热门问题
    • 最新问题
    • 标签
  • 帮助
主页 / 问题

问题[angular4]

Martin Hope
Sergei R
Asked: 2020-11-01 04:52:56 +0000 UTC

如果字段具有有效值,角度材料如何手动将字段标记为无效(并将其重新着色为红色)

  • 0

注册表单,字段被填写并发送到服务器。服务器发送电子邮件已忙的响应。然后我想将电子邮件字段突出显示为无效,但该字段中的值支持电子邮件格式并被验证器识别为有效。

在此处输入图像描述

尝试了不同的变化

this.registerForm.controls['email'].setErrors({ invalid: true, valid: false })

但该领域没有着色。怎么做?

注册.component.ts

export class RegistrationComponent implements OnInit {

  public registerForm: FormGroup
  public spinnerShow = false
  public errMsg: String
  public bothErrMsg: String.

  constructor(
    ...
    private matDialogRef: MatDialogRef<RegistrationComponent>,
    private fb: FormBuilder
  ) {}

  ngOnInit() {
    this.registerForm = this.fb.group({
      email: ['', [FormValidationService.emailValidator]],
      password: this.fb.group({
        pwd: ['', [FormValidationService.passwordValidator]],
        confirm: ['', [FormValidationService.passwordValidator]],
      }, {validator: FormValidationService.confirmValidator('pwd', 'confirm')}),
      username: ['', [FormValidationService.shortStringValidator]],
    })
  }

  register() {
    this.spinnerShow = !this.spinnerShow
    const regData = this.registerForm.value
    regData.confirm = this.registerForm.value.password.confirm
    regData.password = this.registerForm.value.password.pwd

    this.auth.registration(regData).subscribe(
      (res: any) => {
        if (res.error) {
          this.spinnerShow = !this.spinnerShow
          const messages = res.messages
          for (const key in messages) {
            if (messages.hasOwnProperty(key)) {
              if (key === 'both') {
                this.bothErrMsg = messages[key]
                this.registerForm.controls['email'].setErrors({ notUnique: true })
              } else {
                this.registerForm.controls[key].setErrors({ errMsg: messages[key] })
              }
            }
          }
        } else {
          this.lc.setItem('user', res.user)
          this.matDialogRef.close()
        }
      },
      error => {
        console.log(error) // TODO
        this.spinnerShow = !this.spinnerShow
      }
    )
  }
}

注册.component.html

<div class="container">
  <h3>Register new user.</h3>
  <form [formGroup]="registerForm" novalidate>
    <mat-form-field>
      <input matInput formControlName="email" placeholder="Email" type="email" required>
      <mat-error *ngIf="registerForm.controls.email.hasError('errMsg') && registerForm.controls.email.touched">
        {{ registerForm.get('email').getError('errMsg') }}
      </mat-error>
    </mat-form-field>

    <div class="error" *ngIf="bothErrMsg !== undefined">{{ bothErrMsg }}</div>

    <button mat-raised-button color="primary" [disabled]="registerForm.invalid == true" (click)="register()">Sign Up</button>
  </form>
</div>

来自服务器的错误(两者都是 serverErrorMsg 尚未重命名为正常名称)。服务器返回 200 代码和错误消息(如果有)。 在此处输入图像描述

angular4
  • 1 个回答
  • 10 Views
Martin Hope
Ara Chinaryan
Asked: 2020-05-18 22:48:51 +0000 UTC

https://angular.io 网站上的链接如何工作

  • 1

要将用户重定向到另一个页面,我使用Routing & Navigation。显示Inspect Element代码

<a _ngcontent-c0="" routerlink="/heroes" routerlinkactive="active">Heroes</a>

但是当我查看Inspect Element网站时https://angular.io,我看到了

<a class="nav-link" href="docs" title="Docs">Docs</a>

在不刷新页面的情况下如何工作,同上href="docs"?

不要告诉我怎么做?

angular4
  • 1 个回答
  • 10 Views
Martin Hope
QWERTY
Asked: 2020-05-04 06:02:00 +0000 UTC

为什么数据没有更新?

  • 0

创建了一个在单击按钮时执行集合的服务

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

@Injectable()
export class DataService {
  constructor() { }

  private data;

  setData(data) {
    this.data = data;
  }

  getData() {
    return this.data;
  }
}

在另一个文件中,当单击按钮时,调用此服务的获取

this.dataService.getData()

但由于某种原因,数据没有更新......因为它是空的,它仍然存在,尽管如果你从控制台调用它,那么一切正常......我需要使用 Observbl 吗?你能举例说明我在这种情况下如何使用它吗?

angular4
  • 2 个回答
  • 10 Views
Martin Hope
Nevega
Asked: 2020-04-06 20:30:22 +0000 UTC

Angular2如何显示模态窗口?

  • 0

你好。一般是 Angular 和 JS 的新手。

所以。有清晰的用户界面。此页面组件中调用方法的支持者上的按钮:

changeQty(restQty: number, uidItem: string)
  {    
    this.itemQtyUpdateService.updateItemQty(uidItem, restQty)
      .subscribe(
      (item: Item[]) => {
      this.item = item;
     //  тут  вызываем модальное окно
}

当该服务完成后,您需要打开一个模块窗口,其中包含来自该方法的“项目”对象的数据。

在徒劳的尝试中,该指令被创建:

import { Directive } from '@angular/core';
import { ElementRef } from '@angular/core/';
import { OnInit } from '@angular/core/';

@Directive({
  selector: '[appModal]'
})
export class ModalDirective implements OnInit { 

  constructor(private element: ElementRef) { }

  ngOnInit(): void {
    console.log(this.element);
    this.element.nativeElement.clrModalOpen = 'opened';
  }

  showModal() {
    this.element.nativeElement.clrModalOpen = 'true';
    console.log(this.element);
  }
}

在其中创建了 showModal () 方法,在我看来,它将“clrModalOpen”元素属性的值更改为激活窗口。这是 Clarity ui 包中的模态窗口代码:

<clr-modal appModal  [(clrModalOpen)]="opend" [clrModalClosable]="false">
  <h3 class="modal-title">No "x" in the top-right corner</h3>
  <div class="modal-body">
    <p> Для </p>
    <p> По заказу </p>
  </div>
  <div class="modal-footer">
    <button type="button" class="btn btn-primary" (click)="opened = false">
      Я все правильно положил!
    </button>
  </div>
</clr-modal>

此代码位于应调用它的 HTML 页面的末尾。


我从以下逻辑着手:我在 html 代码中创建一个元素 - 我将指令绑定到它 - 在指令中我创建更改其状态的方法 - 我根据需要从主组件调用指令的方法。

我究竟做错了什么 ?

angular4
  • 2 个回答
  • 10 Views
Martin Hope
Ara Chinaryan
Asked: 2020-11-21 16:18:31 +0000 UTC

如何在 Angular 4 的 HTTP PUT 请求中发送表单数据?

  • 0

我正在尝试提交更新的用户数据的表单数据,但它似乎不起作用

{ "name":"User", "status":1 }

如何告诉 Angular 它是什么

<input type="text" [value]="user.name" name="name">

这是输入

服务.ts

updateProductData(dataUrl, id){
        let url = ${environment.endpoint}/${dataUrl}/${id}  ;
        let header =  new HttpHeaders()
            .set("Authorization", "Bearer " + this.token)
            .set("Accept", "application/json");

        return this.http.put(url, {
            "name":"User",
            "status":1
        },{
            headers: header
        });
    }
angular4
  • 1 个回答
  • 10 Views

Sidebar

Stats

  • 问题 10021
  • Answers 30001
  • 最佳答案 8000
  • 用户 6900
  • 常问
  • 回答
  • Marko Smith

    我看不懂措辞

    • 1 个回答
  • Marko Smith

    请求的模块“del”不提供名为“default”的导出

    • 3 个回答
  • Marko Smith

    "!+tab" 在 HTML 的 vs 代码中不起作用

    • 5 个回答
  • Marko Smith

    我正在尝试解决“猜词”的问题。Python

    • 2 个回答
  • Marko Smith

    可以使用哪些命令将当前指针移动到指定的提交而不更改工作目录中的文件?

    • 1 个回答
  • Marko Smith

    Python解析野莓

    • 1 个回答
  • Marko Smith

    问题:“警告:检查最新版本的 pip 时出错。”

    • 2 个回答
  • Marko Smith

    帮助编写一个用值填充变量的循环。解决这个问题

    • 2 个回答
  • Marko Smith

    尽管依赖数组为空,但在渲染上调用了 2 次 useEffect

    • 2 个回答
  • Marko Smith

    数据不通过 Telegram.WebApp.sendData 发送

    • 1 个回答
  • Martin Hope
    Alexandr_TT 2020年新年大赛! 2020-12-20 18:20:21 +0000 UTC
  • Martin Hope
    Alexandr_TT 圣诞树动画 2020-12-23 00:38:08 +0000 UTC
  • Martin Hope
    Air 究竟是什么标识了网站访问者? 2020-11-03 15:49:20 +0000 UTC
  • Martin Hope
    Qwertiy 号码显示 9223372036854775807 2020-07-11 18:16:49 +0000 UTC
  • Martin Hope
    user216109 如何为黑客设下陷阱,或充分击退攻击? 2020-05-10 02:22:52 +0000 UTC
  • Martin Hope
    Qwertiy 并变成3个无穷大 2020-11-06 07:15:57 +0000 UTC
  • Martin Hope
    koks_rs 什么是样板代码? 2020-10-27 15:43:19 +0000 UTC
  • Martin Hope
    Sirop4ik 向 git 提交发布的正确方法是什么? 2020-10-05 00:02:00 +0000 UTC
  • Martin Hope
    faoxis 为什么在这么多示例中函数都称为 foo? 2020-08-15 04:42:49 +0000 UTC
  • Martin Hope
    Pavel Mayorov 如何从事件或回调函数中返回值?或者至少等他们完成。 2020-08-11 16:49:28 +0000 UTC

热门标签

javascript python java php c# c++ html android jquery mysql

Explore

  • 主页
  • 问题
    • 热门问题
    • 最新问题
  • 标签
  • 帮助

Footer

RError.com

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

帮助

© 2023 RError.com All Rights Reserve   沪ICP备12040472号-5