我正在尝试实现自定义验证规则来验证是否选中了复选框.
原文链接:https://www.f2er.com/angularjs/141519.html但是我收到了一个错误
error_handler.js:46 EXCEPTION: _this.subscribe is not a function
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); } }