第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

無法訪問 Angular 8 中父子組件關(guān)系中的父 formControl 對象更改

無法訪問 Angular 8 中父子組件關(guān)系中的父 formControl 對象更改

Helenr 2023-10-10 16:37:55
我創(chuàng)建了一個父組件,如下所示:<form [formGroup] = "cardForm"><app-inputvalidator [controls] = "cardForm.get('name')"></app-inputvalidator>  </form>父 ts 文件import { Component, OnInit } from '@angular/core';import { FormGroup, FormControl,Validators } from '@angular/forms';@Component({  selector: 'app-card-form',  templateUrl: './card-form.component.html',  styleUrls: ['./card-form.component.css']})export class CardFormComponent implements OnInit {  nameFormControl ;   cardForm =  new FormGroup({    name: new FormControl('', [Validators.minLength(5),Validators.maxLength(25)])  });  constructor() {   } ngOnInit(): void {     this.nameFormControl = this.cardForm.get('name');            }}我將 nameFormControls 傳遞給子組件并在模板和類中訪問它,如下所示:輸入驗證器.ts import { Component, OnInit, Input } from '@angular/core'; import { FormControl} from '@angular/forms'; @Component({  selector: 'app-inputvalidator',  templateUrl: './inputvalidator.component.html',  styleUrls: ['./inputvalidator.component.css']}) export class InputvalidatorComponent implements OnInit { @Input() controls: FormControl; constructor() { } ngOnInit(): void { }}輸入驗證器.html  <input [formControlName] = "controls"    <br>  <div>{{ controls.errors | json}}</div> 該項目已成功編譯,沒有錯誤。我將controls.errors 的值設(shè)置為始終為空。為什么當名稱輸入框中的值發(fā)生變化時,無法使用字符串插值打印對象controls.errors?
查看完整描述

1 回答

?
互換的青春

TA貢獻1797條經(jīng)驗 獲得超6個贊

你得到 null 因為你沒有放置必需的驗證器,如果有值并且該值無效,則min,maxLength驗證器將返回錯誤,如果該值為 null 或空字符串,這將被視為有效


查看完整回答
反對 回復(fù) 2023-10-10
  • 1 回答
  • 0 關(guān)注
  • 107 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號