Tôi đang cố triển khai quy tắc xác thực tùy chỉnh để xác thực xem hộp kiểm có được chọn hay không.Góc 2 - Ngoại lệ: _this.subscribe không phải là chức năng - Xác thực tùy chỉnh
Nhưng tôi nhận được một error_handler.js:46 EXCEPTION: _this.subscribe is not a function
khi tôi cố gắng thêm các validator tùy chỉnh
validator.ts
import { Control } from "angular/common"; interface ValidationResult { [key:string]:any; } export class CustomValidators { static validateChecked(c: Control): ValidationResult { return (c.value); } }
Component.ts
import {Component} from '@angular/core'; import { FormBuilder, FormGroup, Validators, FormControl, } from '@angular/forms'; import { CustomValidators } from './validators.ts' @Component({ selector: 'wizard', templateUrl: './template.html', }) /** * @todo - check how first select is automatically active * @todo - export form presets to form class */ export class Wizard { myForm: FormGroup; privacy: boolean; // Prefilling the FormBuilder constructor(private horizonService: HorizonService, fb: FormBuilder) { this.myForm = fb.group({ 'privacy': ['', Validators.required, CustomValidators.validateChecked], }); } onSubmit(values: string): void { console.log('you submitted value: ', values); } }
Bạn đã tìm thấy một giải pháp? – John