Search code examples
angularangular2-universal

Angular2 forms error when using JavaScriptServices/Universal


I have an Angular2 app that was created using the JavaScriptServices starter.

The problem that I am having is that I get a runtime error if I have a form in a component.

I am importing both FormsModule and ReactiveFormsModule.

My form looks like this...

<form (ngSubmit)="onSubmit()" #loginForm="ngForm" >
...
</form>

The error I am getting is...

Exception: Call to Node module failed with error: Prerendering failed because of error: TypeError: _angular_core.InjectionToken is not a constructor at C:\XXX\ClientApp\dist\main-server.js:35055:42

What have I missed? My form setup worked perfectly when I was not using the JavaScriptServices starter for server side rendering.


Solution

  • I found the solution. I was using the most up to date version of Angular. It's not yet compatible.

    After reading this GitHub issue page I found that reverting the Angular version fixed the issue https://github.com/angular/angular/issues/13432

    I am now using the below version and all seems well.

     "@angular/common": "2.0.2",
     "@angular/compiler": "2.0.2",
     "@angular/core": "2.0.2",
     "@angular/forms": "2.0.2",
     "@angular/http": "2.0.2",
     "@angular/platform-browser": "2.0.2",
     "@angular/platform-browser-dynamic": "2.0.2",
     "@angular/platform-server": "2.0.2",
     "@angular/router": "3.0.2",