2016-07-27 10:59:40 -07:00
|
|
|
/**
|
|
|
|
|
* @license
|
|
|
|
|
* Copyright Google Inc. All Rights Reserved.
|
|
|
|
|
*
|
|
|
|
|
* Use of this source code is governed by an MIT-style license that can be
|
|
|
|
|
* found in the LICENSE file at https://angular.io/license
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
import {FormErrorExamples as Examples} from './error_examples';
|
|
|
|
|
|
|
|
|
|
export class TemplateDrivenErrors {
|
|
|
|
|
static modelParentException(): void {
|
2016-08-25 00:50:16 -07:00
|
|
|
throw new Error(`
|
2016-07-27 10:59:40 -07:00
|
|
|
ngModel cannot be used to register form controls with a parent formGroup directive. Try using
|
|
|
|
|
formGroup's partner directive "formControlName" instead. Example:
|
|
|
|
|
|
|
|
|
|
${Examples.formControlName}
|
|
|
|
|
|
|
|
|
|
Or, if you'd like to avoid registering this form control, indicate that it's standalone in ngModelOptions:
|
|
|
|
|
|
|
|
|
|
Example:
|
|
|
|
|
|
|
|
|
|
${Examples.ngModelWithFormGroup}`);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static formGroupNameException(): void {
|
2016-08-25 00:50:16 -07:00
|
|
|
throw new Error(`
|
2016-07-27 10:59:40 -07:00
|
|
|
ngModel cannot be used to register form controls with a parent formGroupName or formArrayName directive.
|
|
|
|
|
|
|
|
|
|
Option 1: Use formControlName instead of ngModel (reactive strategy):
|
|
|
|
|
|
|
|
|
|
${Examples.formGroupName}
|
|
|
|
|
|
|
|
|
|
Option 2: Update ngModel's parent be ngModelGroup (template-driven strategy):
|
|
|
|
|
|
|
|
|
|
${Examples.ngModelGroup}`);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static missingNameException() {
|
2016-08-25 00:50:16 -07:00
|
|
|
throw new Error(
|
2016-07-27 10:59:40 -07:00
|
|
|
`If ngModel is used within a form tag, either the name attribute must be set or the form
|
|
|
|
|
control must be defined as 'standalone' in ngModelOptions.
|
|
|
|
|
|
|
|
|
|
Example 1: <input [(ngModel)]="person.firstName" name="first">
|
|
|
|
|
Example 2: <input [(ngModel)]="person.firstName" [ngModelOptions]="{standalone: true}">`);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static modelGroupParentException() {
|
2016-08-25 00:50:16 -07:00
|
|
|
throw new Error(`
|
2016-07-27 10:59:40 -07:00
|
|
|
ngModelGroup cannot be used with a parent formGroup directive.
|
|
|
|
|
|
|
|
|
|
Option 1: Use formGroupName instead of ngModelGroup (reactive strategy):
|
|
|
|
|
|
|
|
|
|
${Examples.formGroupName}
|
|
|
|
|
|
|
|
|
|
Option 2: Use a regular form tag instead of the formGroup directive (template-driven strategy):
|
|
|
|
|
|
|
|
|
|
${Examples.ngModelGroup}`);
|
|
|
|
|
}
|
2018-08-01 07:17:58 +02:00
|
|
|
|
|
|
|
|
static ngFormWarning() {
|
|
|
|
|
console.warn(`
|
|
|
|
|
It looks like you're using 'ngForm'.
|
|
|
|
|
|
|
|
|
|
Support for using the 'ngForm' element selector has been deprecated in Angular v6 and will be removed
|
|
|
|
|
in Angular v9.
|
|
|
|
|
|
|
|
|
|
Use 'ng-form' instead.
|
|
|
|
|
|
|
|
|
|
Before:
|
|
|
|
|
<ngForm #myForm="ngForm">
|
|
|
|
|
|
|
|
|
|
After:
|
|
|
|
|
<ng-form #myForm="ngForm">
|
|
|
|
|
`);
|
|
|
|
|
}
|
2016-08-10 15:55:18 -07:00
|
|
|
}
|