错误:在Angular2中找不到'undefined'的NgModule元数据

时间:2017-06-11 16:57:14

标签: javascript angular

请在下方找到我的代码,当我添加以下行

时开始面对此问题
platformBrowserDynamic().bootstrapModule(AppModule);

app.module.ts

import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { FormsModule } from '@angular/forms';
import { HttpModule } from '@angular/http';

import { AppComponent } from './app.component';

@NgModule({
  declarations: [
    AppComponent
  ],
  imports: [
    BrowserModule,
    FormsModule,
    HttpModule
  ],
  providers: [],
  bootstrap: [AppComponent]
})
export class AppModule { }

app.component.ts

import { Component } from '@angular/core';
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
import { AppModule } from './app.module';
import { HTTPUserService } from "./app.service";

@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.css'],
  providers: [HTTPUserService]
})
export class AppComponent {
  title = 'app works!';
  getData:string;

  constructor(private _httpService:HTTPUserService){}

  onGet() {
    this._httpService.getUserData()
        .subscribe(
            data => this.getData = data,
            error => alert(error),
            () => console.log("Finished!")
        );
  }
}

platformBrowserDynamic().bootstrapModule(AppModule);

1 个答案:

答案 0 :(得分:0)

为什么要在组件中引导应用程序?在外部文件中执行此操作。通常这是在main.ts文件中完成的,只知道AppModule的存在而没有别的