我想使用rc5中提供的表单,但我发现很难更新到该版本。我尝试按照本教程http://blog.thoughtram.io/angular/2016/06/22/model-driven-forms-in-angular-2.html进行操作,但它不适用于rc3
这是我的boot.ts
import { bootstrap } from '@angular/platform-browser-dynamic';
import {AppComponent} from "./app.component";
import { provideRouter } from '@angular/router';
import {FORM_PROVIDERS, LocationStrategy, HashLocationStrategy} from '@angular/common';
import { HTTP_PROVIDERS } from '@angular/http';
import { AUTH_PROVIDERS } from 'angular2-jwt';
import { AuthGuard } from './common/auth.guard';
import {routes} from "./app.routes";
import {provide} from "@angular/core";
bootstrap(
AppComponent,
[
provideRouter(routes),
FORM_PROVIDERS,
HTTP_PROVIDERS,
AUTH_PROVIDERS,
AuthGuard,
{provide: LocationStrategy, useClass: HashLocationStrategy}
]
);
我知道我应该@NgModule,但我不知道如何改写它。
我该如何重写?
答案 0 :(得分:0)
您的main.ts
应如下所示:
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
import { AppModule } from './app/app.module';
platformBrowserDynamic().bootstrapModule(AppModule);
您需要创建app.module.ts
,看起来应该是这样,但我无法100%肯定:
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { HttpModule } from '@angular/http';
import { FormsModule, ReactiveFormsModule } from '@angular/forms';
import { LocationStrategy, HashLocationStrategy } from '@angular/common';
import { AuthGuard } from './common/auth.guard';
import { AppComponent } from './app.component';
import { routing } from './app.routing';
@NgModule({
imports: [
BrowserModule,
HttpModule,
FormsModule,
ReactiveFormsModule
routing,
],
declarations: [
AppComponent
],
bootstrap: [AppComponent],
providers: [
AuthGuard,
{ provide: LocationStrategy, useClass: HashLocationStrategy }
]
})
export class AppModule { }
我不确定AUTH_PROVIDES
,您可以查看如何在RC5 + here中使用angular2-jwt
。
有关迁移到RC5 +的详细信息,请查看官方RC4 to RC5 Migration doc以及Angular Modules doc以了解RC5更改。您还可以在Angular 2 GitHub官方存储库中阅读changelog。