Angular应用程序无法通过Docker加载

时间:2018-09-07 14:25:09

标签: angular docker dockerfile

我有一个Angular应用程序,当我从命令行执行ng serve时,它运行得很好。但是,当我将应用程序放置在Docker容器中并尝试运行该容器时,我在DOM中收到此错误(只是摘录):

  Uncaught Error: Template parse errors:
    Can't bind to 'formGroup' since it isn't a known property of 'form'. ("
      <div class="col-md-6 offset-md-3">
        <h2>Register new User</h2>
        <form [ERROR ->][formGroup]="registerForm" (ngSubmit)="onSubmit()">
          <div class="form-group">
            "): ng:///AppModule/RegisterComponent.html@5:14
     No provider for ControlContainer ("
      <div class="col-md-6 offset-md-3">
        <h2>Register new User</h2>
        [ERROR ->]<form [formGroup]="registerForm" (ngSubmit)="onSubmit()">
          <div class="form-group">
      "): ng:///AppModule/RegisterComponent.html@5:8
    No provider for NgControl ("
          <div class="form-group">
            <label>First Name</label>
            [ERROR ->]<input type="text" formControlName="firstName" 
    class="form-control" [ngClass]="{ 'is-invalid': submit"): ng:///AppModule/RegisterComponent.html@8:12
    No provider for NgControl ("
          <div class="form-group">
            <label>Last Name</label>
            [ERROR ->]<input type="text" formControlName="lastName" class="form-control" [ngClass]="{ 'is-invalid': submitt"): ng:///AppModule/RegisterComponent.html@15:12
ng:///AppModule/RegisterComponent.html@39:12
    at syntaxError (compiler.js:215)
    at 




    TemplateParser.push../node_modules/@angular/compiler/fesm5/compiler.js.TemplateParser.parse (compiler.js:14702)
        at JitCompiler.push../node_modules/@angular/compiler/fesm5/compiler.js.JitCompiler._parseTemplate (compiler.js:22709)

我的Dockerfile(正在正确的位置构建)如下:

# Stage 1 Build
FROM node:8.11.3
RUN mkdir /usr/src/app
WORKDIR /usr/src/app
ENV PATH ./node_modules/bin:$PATH
COPY package*.json ./
RUN npm install
RUN npm install -g @angular/cli@6.0.8
COPY . /usr/src/app
CMD ng serve --host 0.0.0.0

#Stage 2
FROM nginx:alpine
COPY nginx.conf /etc/nginx/nginx.conf
WORKDIR /usr/share/nginx/html
COPY dist/ .

到目前为止,我研究的许多解决方案都涉及对app.module.ts文件进行更改,以允许导入和导出FormsModuleReactiveFormsModule

 exports: [FormsModule, ReactiveFormsModule, CommonModule],
 imports: [
BrowserModule,
FormsModule,
HttpClientModule,
HttpModule,
ReactiveFormsModule,
CommonModule,
RouterModule.forRoot(appRoutes)

但是我仍然无法通过Docker来解决这个问题。过去有人遇到过这个问题吗?

0 个答案:

没有答案