Javascript 角度5:错误:Can';t解决'@角度/平台浏览器/src/browser';

Javascript 角度5:错误:Can';t解决'@角度/平台浏览器/src/browser';,javascript,angular,Javascript,Angular,我正在尝试创建一个5下的登记表。执行此操作时,我得到一个错误: /src/app/pages/auth admin/auth-admin.module.ts未找到模块: 错误:无法解析“@angular/platform browser/src/browser” 我如何解决这个问题 短暂性脑缺血发作 这就是我在angular下跑步的原因 Angular CLI: 1.6.1 Node: 8.9.4 OS: win32 x64 Angular: 5.1.1 ... animations, comm

我正在尝试创建一个5下的登记表。执行此操作时,我得到一个错误:

/src/app/pages/auth admin/auth-admin.module.ts未找到模块: 错误:无法解析“@angular/platform browser/src/browser”

我如何解决这个问题

短暂性脑缺血发作

这就是我在angular下跑步的原因

Angular CLI: 1.6.1
Node: 8.9.4
OS: win32 x64
Angular: 5.1.1
... animations, common, compiler, compiler-cli, core, forms
... http, language-service, platform-browser
... platform-browser-dynamic, router

@angular/cli: 1.6.1
@angular-devkit/build-optimizer: 0.0.38
@angular-devkit/core: 0.0.23
@angular-devkit/schematics: 0.0.42
@ngtools/json-schema: 1.1.0
@ngtools/webpack: 1.9.1
@schematics/angular: 0.1.13
typescript: 2.4.2
webpack: 3.10.0
目录设置如下所示:

错误消息

Failed to compile.

./src/app/pages/auth-admin/auth-admin.module.ts
Module not found: Error: Can't resolve '@angular/platform-browser/src/browser' in 'C:\WORK\AppAngularDev\ContractorsClub\src\app\pages\auth-admin'
 @ ./src/app/pages/auth-admin/auth-admin.module.ts 19:0-70
 @ ./src/$$_lazy_route_resource lazy
 @ ./node_modules/@angular/core/esm5/core.js
 @ ./src/main.ts
 @ multi webpack-dev-server/client?http://0.0.0.0:0 ./src/main.ts
ERROR Error: Uncaught (in promise): Error: Template parse errors:
Can't bind to 'ngClass' since it isn't a known property of 'input'. ("            <input type="text"  [(ngModel)]="firstname" #userFirstname="ngModel"   
                [ERROR ->][ngClass]="{'is-invalid' : userFirstname.errors && userFirstname.touched }" 
                id="firs"): ng:///AuthAdminModule/AdminRegisterFormComponent.html@19:16
Error: Template parse errors:
Can't bind to 'ngClass' since it isn't a known property of 'input'. ("            <input type="text"  [(ngModel)]="firstname" #userFirstname="ngModel"   
                [ERROR ->][ngClass]="{'is-invalid' : userFirstname.errors && userFirstname.touched }" 
                id="firs"): ng:///AuthAdminModule/AdminRegisterFormComponent.html@19:16
    at syntaxError (compiler.js:485)
    at TemplateParser.parse (compiler.js:24631)
    at JitCompiler._parseTemplate (compiler.js:34442)
    at JitCompiler._compileTemplate (compiler.js:34417)
    at eval (compiler.js:34318)
    at Set.forEach (<anonymous>)
    at JitCompiler._compileComponents (compiler.js:34318)
    at eval (compiler.js:34188)
    at Object.then (compiler.js:474)
    at JitCompiler._compileModuleAndComponents (compiler.js:34187)
    at syntaxError (compiler.js:485)
    at TemplateParser.parse (compiler.js:24631)
    at JitCompiler._parseTemplate (compiler.js:34442)
    at JitCompiler._compileTemplate (compiler.js:34417)
    at eval (compiler.js:34318)
    at Set.forEach (<anonymous>)
    at JitCompiler._compileComponents (compiler.js:34318)
    at eval (compiler.js:34188)
    at Object.then (compiler.js:474)
    at JitCompiler._compileModuleAndComponents (compiler.js:34187)
    at resolvePromise (zone.js:824)
    at resolvePromise (zone.js:795)
    at eval (zone.js:873)
    at ZoneDelegate.invokeTask (zone.js:425)
    at Object.onInvokeTask (core.js:4744)
    at ZoneDelegate.invokeTask (zone.js:424)
    at Zone.runTask (zone.js:192)
    at drainMicroTaskQueue (zone.js:602)
    at <anonymous>
defaultErrorLogger @ core.js:1427

[... snip ...]
来自javascript端的错误消息

Failed to compile.

./src/app/pages/auth-admin/auth-admin.module.ts
Module not found: Error: Can't resolve '@angular/platform-browser/src/browser' in 'C:\WORK\AppAngularDev\ContractorsClub\src\app\pages\auth-admin'
 @ ./src/app/pages/auth-admin/auth-admin.module.ts 19:0-70
 @ ./src/$$_lazy_route_resource lazy
 @ ./node_modules/@angular/core/esm5/core.js
 @ ./src/main.ts
 @ multi webpack-dev-server/client?http://0.0.0.0:0 ./src/main.ts
ERROR Error: Uncaught (in promise): Error: Template parse errors:
Can't bind to 'ngClass' since it isn't a known property of 'input'. ("            <input type="text"  [(ngModel)]="firstname" #userFirstname="ngModel"   
                [ERROR ->][ngClass]="{'is-invalid' : userFirstname.errors && userFirstname.touched }" 
                id="firs"): ng:///AuthAdminModule/AdminRegisterFormComponent.html@19:16
Error: Template parse errors:
Can't bind to 'ngClass' since it isn't a known property of 'input'. ("            <input type="text"  [(ngModel)]="firstname" #userFirstname="ngModel"   
                [ERROR ->][ngClass]="{'is-invalid' : userFirstname.errors && userFirstname.touched }" 
                id="firs"): ng:///AuthAdminModule/AdminRegisterFormComponent.html@19:16
    at syntaxError (compiler.js:485)
    at TemplateParser.parse (compiler.js:24631)
    at JitCompiler._parseTemplate (compiler.js:34442)
    at JitCompiler._compileTemplate (compiler.js:34417)
    at eval (compiler.js:34318)
    at Set.forEach (<anonymous>)
    at JitCompiler._compileComponents (compiler.js:34318)
    at eval (compiler.js:34188)
    at Object.then (compiler.js:474)
    at JitCompiler._compileModuleAndComponents (compiler.js:34187)
    at syntaxError (compiler.js:485)
    at TemplateParser.parse (compiler.js:24631)
    at JitCompiler._parseTemplate (compiler.js:34442)
    at JitCompiler._compileTemplate (compiler.js:34417)
    at eval (compiler.js:34318)
    at Set.forEach (<anonymous>)
    at JitCompiler._compileComponents (compiler.js:34318)
    at eval (compiler.js:34188)
    at Object.then (compiler.js:474)
    at JitCompiler._compileModuleAndComponents (compiler.js:34187)
    at resolvePromise (zone.js:824)
    at resolvePromise (zone.js:795)
    at eval (zone.js:873)
    at ZoneDelegate.invokeTask (zone.js:425)
    at Object.onInvokeTask (core.js:4744)
    at ZoneDelegate.invokeTask (zone.js:424)
    at Zone.runTask (zone.js:192)
    at drainMicroTaskQueue (zone.js:602)
    at <anonymous>
defaultErrorLogger @ core.js:1427

[... snip ...]
验证管理模块.ts

import { Component, OnInit, ViewEncapsulation } from '@angular/core';
import { HttpErrorResponse } from '@angular/common/http';
import { FormGroup, FormBuilder, Validators, FormControl } from '@angular/forms';
import { ElementRef } from '@angular/core/src/linker/element_ref';
// import { FormsModule } from '@angular/forms';

@Component({
  selector: 'app-admin-register-form',
  templateUrl: './admin-register-form.component.html',
  styleUrls: ['./admin-register-form.component.scss'],
  encapsulation: ViewEncapsulation.None
})
export class AdminRegisterFormComponent implements OnInit {

  firstname = '';
  lastname = '';
  email = '';
  username = '';
  password = '';
  passwordconf = '';

  constructor() { }

  ngOnInit() {

  }

  ngAfterViewInit() {
    document.getElementById('preloader').classList.add('hide');
  }

  onSubmit(form: ElementRef) {
    console.log("form was submitted");
    console.log(form);
    // { "username":"jwoo", "email":"jwoo@kickboxing.com",  "password":"123456", "firstname":"jason", "lastname":"wu" }

  }
}
import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
import { AdminLoginComponent } from './admin-login/admin-login.component';
import { AdminRegisterComponent } from './admin-register/admin-register.component';
import { AdminDataComponent } from './admin-data/admin-data.component';
import { RouterModule } from '@angular/router';
import { AdminHeaderComponent } from './admin-header/admin-header.component';
import { AdminFooterComponent } from './admin-footer/admin-footer.component';
import { AuthAdminComponent } from 'app/pages/auth-admin/auth-admin.component';
import { AdminRegisterFormComponent } from './admin-register-form/admin-register-form.component';

import { FormsModule }   from '@angular/forms';
import { NgClass } from '@angular/common';
import { BrowserModule } from '@angular/platform-browser/src/browser';



export const routes = [
  { path:'', redirectTo:'admin-login-main', pathMatch:'full' },
  { path: 'admin-login', component: AdminLoginComponent, pathMatch: 'full' },
  { path: 'admin-login-main', component: AuthAdminComponent, pathMatch: 'full' },
  { path: 'admin-register', component: AdminRegisterComponent, pathMatch: 'full' },
  { path: 'admin-data', component: AdminDataComponent, pathMatch: 'full' }
];


@NgModule({
  imports: [
    BrowserModule,
    FormsModule,
    RouterModule.forChild(routes)
  ],
  declarations: [AdminLoginComponent, AdminRegisterComponent, 
    AdminDataComponent, AdminHeaderComponent, 
    AdminFooterComponent, AdminHeaderComponent, AdminFooterComponent, 
    AuthAdminComponent, AdminRegisterFormComponent]
})
export class AuthAdminModule { }

BrowserModule
应在AppModule中导入一次。您不需要在子模块中再次导入它,应该像

import { BrowserModule } from '@angular/platform-browser';
另外,
ngClass
指令构成了
CommonModule
的一部分,它似乎没有导入到您的
AuthAdminModule

@NgModule({
  imports: [
    ...
    CommonModule
  ],
  declarations: [ ... ] 
})
export class AuthAdminModule { }

您在auth-admin.module.ts中错误地导入了BrowserModule

import { BrowserModule } from '@angular/platform-browser';
此外,对于功能模块,您可以导入
CommonModule
module<代码>浏览器模块仅在app.module.ts中需要

import { CommonModule } from '@angular/common';
@NgModule({
  declarations: [
    ...
  ],
  imports: [
    CommonModule,
    ...
  ]
})
export class AuthAdminModule {}

尝试从“@angular/platform browser”导入模块