我最近从RC4升级到RC5,并没有更改任何代码,但应用程序已损坏.这是错误消息:
<html> <head> <script> var pjson = require('./package.json'); document.title = pjson.name; </script> <Meta name="viewport" content="width=device-width,initial-scale=1"> <link rel="stylesheet" href="./node_modules/font-awesome/css/font-awesome.min.css"> <link rel="stylesheet" href="./node_modules/bootstrap/dist/css/bootstrap.min.css"> <link rel="stylesheet" href="./css/global.css"> <!-- 1. Load libraries --> <!-- Polyfill(s) for older browsers --> <script src="node_modules/core-js/client/shim.min.js"></script> <script src="node_modules/zone.js/dist/zone.js"></script> <script src="node_modules/reflect-Metadata/Reflect.js"></script> <script src="node_modules/systemjs/dist/system.src.js"></script> <!-- 2. Configure SystemJS --> <script src="systemjs.config.js"></script> <script> System.import('app/main/bootstrap.js').catch(function(err){ console.error(err); }); </script> <script> var electron = require('electron'); </script> </head> <body> <app-cmp>Loading...</app-cmp> </body> </html>
更新:现在使用Angular-CLI,不再有任何问题.
看起来你必须将ElementRef拉入@NgModule注释的导入部分,例如我在
my app的这个例子中所做的.
如果这对你没有任何意义,那么你需要阅读RC.5对Angular 2所做的重大修改.他们是蠢货.这是documentation for NgModule.你会发现它在Quickstart Docs中使用的一个非常基本的例子.如果我的个人经验有任何迹象,你的应用程序需要进行大修才能使其正常运行.几个小时后我还没有让我的工作再次开始,我的是一个非常基本的应用程序.
// app.module.ts // Angular 2 imports import { NgModule,ElementRef } from '@angular/core'; // <--- Import ElementRef import { BrowserModule } from '@angular/platform-browser'; import { RouterModule } from '@angular/router' import { HTTP_PROVIDERS } from '@angular/http'; import { COMMON_DIRECTIVES } from '@angular/common'; // My components and services (yours will certainly differ) import {PublicPage} from './components/pages/public-page' import {ProtectedPage} from './components/pages/protected-page' import {LoggedoutPage} from "./components/pages/loggedout-page"; import { APP_ROUTES } from './app.routes'; import { WindowService } from './services/window.service'; import { AuthService } from './services/auth.service'; import { CookieService } from './services/cookies.service'; // My main component for this app/module import { AppComponent } from './app.component'; @NgModule({ // Add ElementRef to the module imports below imports: [ ElementRef,BrowserModule,RouterModule.forRoot(APP_ROUTES) ],declarations: [ AppComponent,PublicPage,ProtectedPage,LoggedoutPage ],bootstrap: [ AppComponent ],providers: [ WindowService,AuthService,CookieService,HTTP_PROVIDERS,COMMON_DIRECTIVES ] }) export class AppModule { }
然后我用这样的东西来升级模块:
// main.ts import { platformBrowserDynamic } from '@angular/platform-browser-dynamic'; import { AppModule } from './app.module'; platformBrowserDynamic().bootstrapModule(AppModule);