![](/img/trans.png)
[英]How to start change detection (valueChanges) inside a ControlValueAccessor
我有一個 formControl,我正在嘗試 setValue 然后觸發更改檢測,以便我的其他組件中的valueChanges會得到我在此處設置的更改 - 但它不起作用。 即使我把 emitEvent: true。 不觸發valueChanges ...
[英]How to start change detection (valueChanges) inside a ControlValueAccessor
我有一個 formControl,我正在嘗試 setValue 然后觸發更改檢測,以便我的其他組件中的valueChanges會得到我在此處設置的更改 - 但它不起作用。 即使我把 emitEvent: true。 不觸發valueChanges ...
[英]How to mark as touched a custom input in Angular with ControlValueAccessor?
我想要的是如果用戶單擊提交按鈕但沒有填寫所有輸入,我會將所有輸入標記為已觸摸,因為表單上有一個必需的驗證器,空輸入應該有一個紅色邊框。 問題當我將表單的所有輸入標記為已觸摸時,自定義輸入不會更改,也不會添加類: 只有基本輸入有類,這里是 html 的結果,只有基本輸入顯示紅色邊框: 輸入組件i ...
[英]Angular CustomValueAccesor - input value is not refreshing, when model make changes to value
問題游樂場: https://stackblitz.com/edit/angular-7nuggp 腳步: 將輸入值設置為-1並模糊 - 觸發handleBlur , Math.abs在值上創建 Math.abs,觸發writeValue並將輸入值設置為1 - 正確再次將輸入值設置為-1並模糊 - ...
[英]Custom Control Component Implementing ControlValueAccessor and Validator Not Staying In Sync With Consuming FormGroup
背景: 我有一個自定義的 email 控件組件 ( EmailControlComponent ),它實現了ControlValueAccessor和Validator 。 EmailControlComponent的validate()方法接受單個AbstractControl參數。 根據 An ...
[英]How can I check the validation in my formGroup when i use ControlValueAccessor
我的app.component中有以下代碼,它是父級 TS html 在我的添加代碼描述組件中,我有另一個組 所以現在當頁面加載時,我有兩個需要的輸入代碼。 當我在輸入字段中鍵入內容並單擊“檢查子表單”時,我可以看到group表單有效,因為兩個輸入都有值。如果我沒有在輸入中輸入任何內容,則grou ...
[英]I can't see initial value to ngModel
我有以下可重用組件code-component HTML 我為此實現了控制值訪問器 TS 所以當我從外面使用這個組件時,我會以這種方式使用它 我的問題是當頁面加載時我沒有得到2 。 當我開始打字時,我得到反映了 database.id 屬性中的 ngModel 更改我的錯誤在哪里? 我怎樣才能從一 ...
[英]Angular ControlValueAccessor how to transfert the invalid status?
我已經使用ControlValueAccessor創建了一個自定義輸入,我可以在 formControl 中使用它並且它工作正常。 現在我想知道表單控件何時被認為無效,無法在我的自定義組件內的輸入上顯示紅色邊框。 這是我的自定義輸入:@Component({ selector: 'app-in ...
[英]Angular | ControlValueAccessor to non native Input
是否可以在 Angular 中使用ControlValueAccessor制作自定義表單控件,而不是使用 DOM 的本機元素(如輸入、文本區域、單選按鈕),而是使用普通的 div 和 span? 我在谷歌上徘徊尋找這個特定問題的答案,但不幸的是沒有運氣。 ...
[英]Can you integrate error handling in a control value accessor component
從控制值訪問器的以下設置開始: 表單控件在父組件中定義。 所以我可以將錯誤作為@Input 傳遞給這個'some-datepicker'組件。 但是還有一種方法我不必這樣做,而是將它集成到這個組件本身中? ...
[英]Marking child forms as all touched from parent form
我正在使用 angular 中的 ControlValueAccessor 和 Validator 接口處理 angular 中的出生日期組件。 我已經實現了這些接口所需的所有方法@Component({ selector: 'app-birthdate', templateUrl: './ ...
[英]A custom angular two-state checkbox component issue
我正在嘗試創建一個自定義復選框組件來替換一個舊的 NG Prime 版本,該版本一直在使用,但希望通過添加一些 aria 點並直接利用更多的復選框屬性使其更精簡/更清潔。 我遇到的問題(我猜)是更新值訪問器/ngmodel,並且可以使用一些關於我顯然缺少的指導...... 我認為我所擁有的已經足夠簡 ...
[英]Emit event to component when validators are cleared
我創建了一個自定義輸入組件。 當存在所需的約束(在 OnInit 中計算)時,會顯示其 label。@Component({ selector: 'custom-input', template: `<div *ngIf="isMandatory()">Mandatory< ...
[英]Angular Reactive Forms vs ngModel, which has better performance?
我試圖了解兩者中哪一個具有更好的性能,我猜表單的類型對響應很重要,就我而言,我正在嘗試創建一些 ControlValueAccessor 組件,每個組件都包含一個 mat-autocomplete 字段,目標是使用它在一個更大的響應式表單元素中,我想在 ControlValueAccessor 組 ...
[英]Angular Unit Test: Error: No value accessor for form control
我從我的表單中抽象出每個字段如下(這在開發中有效,但在我的單元測試中無效)// required.control.ts import { FormControl, Validators } from '@angular/forms'; export class RequiredCo ...
[英]Angular custom FormControl with updateOn blur
我有一個反應式表單組,它與 updateOn submit和 updateOn change一起工作得很好。 但是當我切換到 updateOn blur時,在我的自定義表單控件中輸入一個字符后直接觸發所需的錯誤並且永遠不會消失。 此外,當我提交表單時,我的自定義表單控件的所有值都是空的(即使字段已 ...
[英]Angular V11: NullInjectorError: No provider for ControlContainer
我根據本文進行了自定義輸入: medium.com: dont-reinvent-the-wheel 。 這是我的代碼,它處於嚴格模式 ▼// input.component.ts import { Component, Input, ViewChild } from '@angular/core ...
[英]ControlValueAccessor and FormControl Value are out of sync
我在我的輸入上實現了一個mask ,只允許使用特殊格式。 掩碼工作正常,但是當用戶輸入字母時,例如,它會附加到formControl value ,即使該字段沒有顯示它。 閃電戰 ...
[英]Custom MatFormFieldControl not showing initial value in view
檢查stackblitz: https ://stackblitz.com/edit/angular-material-components-demo-5k6gey ? file = src/app/app.component.html 當它有一個初始值時,它不顯示在視圖中,當試圖清除它的值時,它 ...
[英]Angular: Custom form components do not react to value change - like 2 way data binding
所以我正在創建自己的表單組件,它與本文中的問題類似 https://coryrylan.com/blog/angular-custom-form-controls-with-reactive-forms-and-ngmodel 我在那里分叉代碼來說明這一點...... https://stackbl ...
[英]Angular reactive form validate required status in child control
我有一個實現ControlValueAccessor和Validator的自定義組件。 該組件在form中使用,當它在 HTML 中創建時,我在自定義控件上設置了formControlName 。 所有這些都很好,但缺少的部分是讓孩子的input控件知道它應該是必需的。 當必需組件中沒有值時,我正在 ...