1

我正在 Angular 中测试模板驱动的表单。但它给了我这个错误**没有将“exportAs”设置为“ngForm”的指令**我在 app.module.ts 和我的 ....module.ts 中导入了 FormsModule 和 ReactiveFormsModule,这是另一个子模块在我想使用以下行测试的文件所在的文件夹中:

import { FormsModule, ReactiveFormsModule } from '@angular/forms';
和这个:

@NgModule({
    imports: [
        BrowserModule,
        OncosupAppRoutingModule,
        Ng2Webstorage.forRoot({ prefix: 'jhi', separator: '-'}),
        OncosupSharedModule,
        OncosupHomeModule,
        OncosupAdminModule,
        OncosupAccountModule,
        OncosupEntityModule,
        FormsModule,
        ReactiveFormsModule,
    ],
我的表格是这样开始的:

<form name="editForm" role="form" novalidate (ngSubmit)="save()" #editForm="ngForm">

然后,如果您需要更多信息,错误将继续如下。

        Can't bind to 'ngValue' since it isn't a known property of 'option'. ("p
aciente.hospitalId" >
                        <option [ngValue]="null"></option>
                        <option [ERROR ->][ngValue]="hospitalOption.id" *ngFor="
let hospitalOption of hospitals; trackBy: trackHospitalById">{{"): ng:///Dynamic
TestModule/PacienteDialogComponent.html@188:24
        Error: Template parse errors:
            at syntaxError (webpack:///node_modules/@angular/compiler/esm5/compi
ler.js:485:21 <- spec/entry.ts:63150:34)
            at TemplateParser.parse (webpack:///node_modules/@angular/compiler/e
sm5/compiler.js:24661:0 <- spec/entry.ts:87326:19)
            at JitCompiler._parseTemplate (webpack:///node_modules/@angular/comp
iler/esm5/compiler.js:34601:0 <- spec/entry.ts:97266:37)
            at JitCompiler._compileTemplate (webpack:///node_modules/@angular/co
mpiler/esm5/compiler.js:34576:0 <- spec/entry.ts:97241:23)
            at webpack:///node_modules/@angular/compiler/esm5/compiler.js:34477:
47 <- spec/entry.ts:97142:62
            at Set.forEach (<anonymous>)
            at JitCompiler._compileComponents (webpack:///node_modules/@angular/
compiler/esm5/compiler.js:34477:0 <- spec/entry.ts:97142:19)
            at webpack:///node_modules/@angular/compiler/esm5/compiler.js:34365:
0 <- spec/entry.ts:97030:19
            at Object.then (webpack:///node_modules/@angular/compiler/esm5/compi
ler.js:474:32 <- spec/entry.ts:63139:77)
            at JitCompiler._compileModuleAndAllComponents (webpack:///node_modul
es/@angular/compiler/esm5/compiler.js:34363:0 <- spec/entry.ts:97028:26)
        Error: Template parse errors:
        There is no directive with "exportAs" set to "ngForm" ("<form name="edit
Form" role="form" novalidate (ngSubmit)="save()" [ERROR ->]#editForm="ngForm">
            <div class="modal-header">
                <h4 class="modal-title" id="myPacienteLa"): ng:///DynamicTestMod
ule/PacienteDialogComponent.html@0:65
        'jhi-alert-error' is not a known element:
        1. If 'jhi-alert-error' is an Angular component, then verify that it is
part of this module.
        2. If 'jhi-alert-error' is a Web Component then add 'CUSTOM_ELEMENTS_SCH
EMA' to the '@NgModule.schemas' of this component to suppress this message. ("
            </div>
            <div class="modal-body">
                [ERROR ->]<jhi-alert-error></jhi-alert-error>
                <div class="half-block">
                        <div class="form-grou"): ng:///DynamicTestModule/Pacient
eDialogComponent.html@7:8
        Can't bind to 'ngModel' since it isn't a known property of 'input'. ("
        <input type="text" class="form-control" name="nombre" id="field_nombre"
                                [ERROR ->][(ngModel)]="paciente.nombre" required
/>
                            <div [hidden]="!(editForm.controls.nombre?.dir"): ng
:///DynamicTestModule/PacienteDialogComponent.html@12:17
        Can't bind to 'ngModel' since it isn't a known property of 'input'. ("
  <input type="text" class="form-control" name="apellidos" id="field_apellidos"
                                [ERROR ->][(ngModel)]="paciente.apellidos" requi
red/>
                            <div [hidden]="!(editForm.controls.apellido"): ng://
/DynamicTestModule/PacienteDialogComponent.html@24:17
        There is no directive with "exportAs" set to "ngbDatepicker" ("t id="fie
ld_fechaNacimiento" type="text" class="form-control" name="fechaNacimiento" ngbD
atepicker  [ERROR ->]#fechaNacimientoDp="ngbDatepicker" [(ngModel)]="paciente.fe
chaNacimiento"
                                required/"): ng:///DynamicTestModule/PacienteDia
logComponent.html@38:122
        Can't bind to 'ngModel' since it isn't a known property of 'input'. ("te
xt" class="form-control" name="fechaNacimiento" ngbDatepicker  #fechaNacimientoD
p="ngbDatepicker" [ERROR ->][(ngModel)]="paciente.fechaNacimiento"
                                required/>
                                <span class="in"): ng:///DynamicTestModule/Pacie
nteDialogComponent.html@38:157
        Can't bind to 'ngModel' since it isn't a known property of 'select'. ("p
aciente.sexo" for="field_sexo">Sexo</label>
                            <select class="form-control" name="sexo" [ERROR ->][
(ngModel)]="paciente.sexo" id="field_sexo"  required>
                                <option value="VARON">{{'onc"): ng:///DynamicTes
tModule/PacienteDialogComponent.html@53:54
        The pipe 'translate' could not be found ("o" [(ngModel)]="paciente.sexo"
 id="field_sexo"  required>
                                <option value="VARON">{{[ERROR ->]'oncosupApp.Se
xo.VARON' | translate}}</option>
                                <option value="MUJER">{{'oncosupApp."): ng:///Dy
namicTestModule/PacienteDialogComponent.html@54:41
        The pipe 'translate' could not be found ("="VARON">{{'oncosupApp.Sexo.VA
RON' | translate}}</option>
                                <option value="MUJER">{{[ERROR ->]'oncosupApp.Se
xo.MUJER' | translate}}</option>
                            </select>
                            <div [hidden]="!"): ng:///DynamicTestModule/Paciente
DialogComponent.html@55:41
        Can't bind to 'ngModel' since it isn't a known property of 'input'. (">
                            <input type="text" class="form-control" name="nhc" i
d="field_nhc"
                                [ERROR ->][(ngModel)]="paciente.nhc" maxlength="
38" pattern="[0-9]+"/>
                            <div [hidden]="!(editForm."): ng:///DynamicTestModul
e/PacienteDialogComponent.html@70:17
        Can't bind to 'ngModel' since it isn't a known property of 'input'. (">
                            <input type="text" class="form-control" name="nss" i
d="field_nss"
                                [ERROR ->][(ngModel)]="paciente.nss" maxlength="
20"/>
                            <div [hidden]="!(editForm.controls.nss?.dir"): ng://
/DynamicTestModule/PacienteDialogComponent.html@85:17
        Can't bind to 'ngModel' since it isn't a known property of 'input'. ("e=
"text" class="form-control" name="tarjetaSanitaria" id="field_tarjetaSanitaria"
                                [ERROR ->][(ngModel)]="paciente.tarjetaSanitaria
" maxlength="20"/>
                            <div [hidden]="!(editForm.cont"): ng:///DynamicTestM
odule/PacienteDialogComponent.html@99:17
        Can't bind to 'ngModel' since it isn't a known property of 'input'. ("
                            <input type="text" class="form-control" name="cipa"
id="field_cipa"
                                [ERROR ->][(ngModel)]="paciente.cipa" maxlength=
"20"/>
                            <div [hidden]="!(editForm.controls.cipa?.d"): ng:///
DynamicTestModule/PacienteDialogComponent.html@110:17
        Can't bind to 'ngModel' since it isn't a known property of 'input'. ("
    <input type="text" class="form-control" name="telefono" id="field_telefono"
                                [ERROR ->][(ngModel)]="paciente.telefono" />
                        </div>
                        <div class="form-group half-item">
        "): ng:///DynamicTestModule/PacienteDialogComponent.html@125:17
        Can't bind to 'ngModel' since it isn't a known property of 'input'. ("-z
A-Z0-9-]+(\.[a-zA-Z0-9-]+)*" class="form-control" name="email" id="field_email"
                                [ERROR ->][(ngModel)]="paciente.email" />
                        </div>
                </div>
        "): ng:///DynamicTestModule/PacienteDialogComponent.html@130:17
        Can't bind to 'ngModel' since it isn't a known property of 'select'. ("d
</label>
                        <select class="form-control" id="field_nacionalidad" nam
e="nacionalidad" [ERROR ->][(ngModel)]="paciente.nacionalidadId" >
                            <option [ngValue]="null"></option>
            "): ng:///DynamicTestModule/PacienteDialogComponent.html@137:89
        Can't bind to 'ngValue' since it isn't a known property of 'option'. ("i
onalidad" name="nacionalidad" [(ngModel)]="paciente.nacionalidadId" >
                            <option [ERROR ->][ngValue]="null"></option>
                            <option [ngValue]="nacionalidadOption.id" *ngFor="le
t"): ng:///DynamicTestModule/PacienteDialogComponent.html@138:28
        Can't bind to 'ngValue' since it isn't a known property of 'option'. ("i
onalidadId" >
                            <option [ngValue]="null"></option>
                            <option [ERROR ->][ngValue]="nacionalidadOption.id"
*ngFor="let nacionalidadOption of nacionalidads; trackBy: trackNaci"): ng:///Dyn
amicTestModule/PacienteDialogComponent.html@139:28
        Can't bind to 'ngModel' since it isn't a known property of 'select'. ("f
ield_etnia">Etnia</label>
                            <select class="form-control" id="field_etnia" name="
etnia" [ERROR ->][(ngModel)]="paciente.etniaId" >
                                <option [ngValue]="null"></option>
                             "): ng:///DynamicTestModule/PacienteDialogComponent
.html@144:72
        Can't bind to 'ngValue' since it isn't a known property of 'option'. ("m
-control" id="field_etnia" name="etnia" [(ngModel)]="paciente.etniaId" >
                                <option [ERROR ->][ngValue]="null"></option>
                                <option [ngValue]="etniaOption.id" *ngFor="let e
tniaOpti"): ng:///DynamicTestModule/PacienteDialogComponent.html@145:25
        Can't bind to 'ngValue' since it isn't a known property of 'option'. (""
paciente.etniaId" >
                                <option [ngValue]="null"></option>
                                <option [ERROR ->][ngValue]="etniaOption.id" *ng
For="let etniaOption of etnias; trackBy: trackEtniaById">{{etniaOption."): ng://
/DynamicTestModule/PacienteDialogComponent.html@146:25
        Can't bind to 'ngModel' since it isn't a known property of 'select'. ("l
d_comunidadActual" name="comunidadActual" (change)="onComunidadActual(paciente.c
omunidadActualId)" [ERROR ->][(ngModel)]="paciente.comunidadActualId" >
                                <option [ngValue]="null"></option>
                   "): ng:///DynamicTestModule/PacienteDialogComponent.html@155:
149
        Can't bind to 'ngValue' since it isn't a known property of 'option'. ("l
(paciente.comunidadActualId)" [(ngModel)]="paciente.comunidadActualId" >
                                <option [ERROR ->][ngValue]="null"></option>
                                <option [ngValue]="comunidadAutonomaOption.id" *
ngFor="l"): ng:///DynamicTestModule/PacienteDialogComponent.html@156:25
        Can't bind to 'ngValue' since it isn't a known property of 'option'. ("c
omunidadActualId" >
                                <option [ngValue]="null"></option>
                                <option [ERROR ->][ngValue]="comunidadAutonomaOp
tion.id" *ngFor="let comunidadAutonomaOption of comunidadesAutonomas; t"): ng://
/DynamicTestModule/PacienteDialogComponent.html@157:25
        Can't bind to 'ngModel' since it isn't a known property of 'select'. ("l
abel>
                            <select class="form-control" id="field_provinciaActu
al" name="provinciaActual" [ERROR ->][(ngModel)]="paciente.provinciaActualId" >
                                <option [ngValue]="null"></option>
                   "): ng:///DynamicTestModule/PacienteDialogComponent.html@162:
92
        Can't bind to 'ngValue' since it isn't a known property of 'option'. ("A
ctual" name="provinciaActual" [(ngModel)]="paciente.provinciaActualId" >
                                <option [ERROR ->][ngValue]="null"></option>
                                <option [ngValue]="provinciaPaisOption.id" *ngFo
r="let p"): ng:///DynamicTestModule/PacienteDialogComponent.html@163:25
        Can't bind to 'ngValue' since it isn't a known property of 'option'. ("p
rovinciaActualId" >
                                <option [ngValue]="null"></option>
                                <option [ERROR ->][ngValue]="provinciaPaisOption
.id" *ngFor="let provinciaPaisOption of provinciasPaisActual; trackBy: "): ng://
/DynamicTestModule/PacienteDialogComponent.html@164:25
        Can't bind to 'ngModel' since it isn't a known property of 'select'. ("i
co" name="comunidadDiagnostico" (change)="onComunidadDiagnostico(paciente.comuni
dadDiagnosticoId)" [ERROR ->][(ngModel)]="paciente.comunidadDiagnosticoId" >
                            <option [ngValue]="null"></optio"): ng:///DynamicTes
tModule/PacienteDialogComponent.html@171:172
        Can't bind to 'ngValue' since it isn't a known property of 'option'. ("m
unidadDiagnosticoId)" [(ngModel)]="paciente.comunidadDiagnosticoId" >
                            <option [ERROR ->][ngValue]="null"></option>
                            <option [ngValue]="comunidadAutonomaOption.id" *ngFo
r"): ng:///DynamicTestModule/PacienteDialogComponent.html@172:28
        Can't bind to 'ngValue' since it isn't a known property of 'option'. ("a
gnosticoId" >
                            <option [ngValue]="null"></option>
                            <option [ERROR ->][ngValue]="comunidadAutonomaOption
.id" *ngFor="let comunidadAutonomaOption of comunidadesAutonomas; t"): ng:///Dyn
amicTestModule/PacienteDialogComponent.html@173:28
        Can't bind to 'ngModel' since it isn't a known property of 'select'. ("
          <select class="form-control" id="field_provinciaDiagnostico" name="pro
vinciaDiagnostico" [ERROR ->][(ngModel)]="paciente.provinciaDiagnosticoId" >
                            <option [ngValue]="null"></optio"): ng:///DynamicTes
tModule/PacienteDialogComponent.html@178:105
        Can't bind to 'ngValue' since it isn't a known property of 'option'. (""
provinciaDiagnostico" [(ngModel)]="paciente.provinciaDiagnosticoId" >
                            <option [ERROR ->][ngValue]="null"></option>
                            <option [ngValue]="provinciaPaisOption.id" *ngFor="l
e"): ng:///DynamicTestModule/PacienteDialogComponent.html@179:28

还有什么我应该知道的吗??


如果每条记录都有打开和关闭日期,如何随时间显示活动记录

如果每条记录都有一个打开和关闭日期,我如何显示每个季度最后一天的活动记录数。我正在使用 IBM Cognos Analytics 11.0.9,而且我比较新……请提示一下……谢谢。

4

3 回答 3

1

在输入字段中..

在你有 [(ngModel)]="aaa" 的地方,你应该有 name="aaa"

ngModel 和 name 必须具有相同的值..

于 2018-05-10T22:53:45.937 回答
0

我有同样的错误,为了解决这个问题,我添加了 FormsModule 导入来测试配置。

您的默认测试应如下所示:

  beforeEach(async(() => {
    TestBed.configureTestingModule({
      declarations: [FormComponent],
      imports: [FormsModule] >>> add this import!
    })
      .compileComponents();
  }));
于 2019-02-20T13:42:18.690 回答
0

您可以尝试将 CommonModule 导入 app.module.ts

import { CommonModule } from '@angular/common';
于 2018-05-10T16:20:45.073 回答