1

我按照这里提到的解决方案仍然遇到异常

Uncaught Error: Template parse errors:
There is no directive with "exportAs" set to "ngbDatepicker" ("   <input class="form-control" placeholder="yyyy-mm-dd" name="dp" [(ngModel)]="model" ngbDatepicker [ERROR ->]#d="ngbDatepicker">
          <div class="input-group-append">
         <button class="btn btn-out"): ng:///LayoutModule/StudentComponent.html@34:107
Can't bind to 'ngModel' since it isn't a known property of 'input'. ("    <div class="col-sm-3">
         <input class="form-control" placeholder="yyyy-mm-dd" name="dp" [ERROR ->][(ngModel)]="model" ngbDatepicker #d="ngbDatepicker">
         <div class="input-group-append">
"): ng:///LayoutModule/StudentComponent.html@34:73
at syntaxError (compiler.js:215)
at TemplateParser.push../node_modules/@angular/compiler/fesm5/compiler.js.TemplateParser.parse (compiler.js:14705)

我的 app.module.ts

    import { BrowserModule } from '@angular/platform-browser';
    import { NgModule, Injectable } from '@angular/core';
    import { FormsModule } from '@angular/forms';
    import { Router, Routes, RouterModule, CanActivateChild, 
    ActivatedRouteSnapshot, RouterStateSnapshot } from "@angular/router";
    import { Observable } from 'rxjs';
    import { NgbModal, NgbModule } from '@ng-bootstrap/ng-bootstrap';

    @NgModule({
    imports: [   
    BrowserModule,
    HttpClientModule,
    HeaderModule,
    LayoutModule,
    FormsModule  ,
    NgbModule.forRoot(),
    RouterModule.forRoot(routes, {useHash: true}),  
  ],
  declarations: [///declare components here]
 })

html

<div class="col-sm-1">
      <label for="dob">DOB</label>
    </div>
    <div class="col-sm-3">
      <input class="form-control" placeholder="yyyy-mm-dd" name="dp" [(ngModel)]="model" ngbDatepicker #d="ngbDatepicker">
      <div class="input-group-append">
        <button class="btn btn-outline-secondary" (click)="d.toggle()" type="button">
          <img src="img/calendar-icon.svg" style="width: 1.2rem; height: 1rem; cursor: pointer;" />
        </button>
      </div>
    </div>
4

0 回答 0