Justin Justin - 4 months ago 66
AngularJS Question

Angular2 forms compile error when using [disableDeprecatedForms(), provideForms()] in bootstrap()

I am trying to build a plain form using AngularJS 2, by following the example in the quick start guide (https://angular.io/docs/ts/latest/guide/forms.html).

When I disable old forms module and enable new forms module as suggested in the bootstrap() function, I'm getting a compile error.

I'm very new to AngularJs. Any help is appreciated. Details are given below:

Upon adding "[ disableDeprecatedForms(), provideForms() ]" to the bootstrap function, it throws up compilation error.

Below is the code I have in main.ts file.



import { bootstrap } from '@angular/platform-browser-dynamic';
import { disableDeprecatedForms, provideForms } from '@angular/forms';
import { AppComponent } from './app.component';

bootstrap(AppComponent,[ appRouterProviders ], [
disableDeprecatedForms(),
provideForms()
] );
/*
bootstrap(AppComponent,[ appRouterProviders ] );
*/





I get the below compilation error if "npm start" is transpiling when I have the above code in main.ts.

If I use the bootstrap() call shown within comments, it compiles without errors, but throws a warning "*It looks like you're using the old forms module...."



[0] app/main.ts(7,1): error TS2346: Supplied parameters do not match any signature of call target.
[0] 9:24:40 PM - Compilation complete. Watching for file changes.





If I start "npm start" with this piece of code in main.ts, npm simply refuses to start and throws up ERR!. Below is the excerpt from npm-debug.log:


11 silly lifecycle angular2-quickstart@1.0.0~start: Args: [ '-c', 'tsc && concurrently "npm run tsc:w" "npm run lite" ' ]
12 silly lifecycle angular2-quickstart@1.0.0~start: Returned: code: 2 signal: null
13 info lifecycle angular2-quickstart@1.0.0~start: Failed to exec start script
14 verbose stack Error: angular2-quickstart@1.0.0 start: `tsc && concurrently "npm run tsc:w" "npm run lite" `
14 verbose stack Exit status 2
14 verbose stack at EventEmitter.<anonymous> (/home/justin/.nvm/versions/node/v6.3.1/lib/node_modules/npm/lib/utils/lifecycle.js:242:16)
14 verbose stack at emitTwo (events.js:106:13)
14 verbose stack at EventEmitter.emit (events.js:191:7)
14 verbose stack at ChildProcess.<anonymous> (/home/justin/.nvm/versions/node/v6.3.1/lib/node_modules/npm/lib/utils/spawn.js:40:14)
14 verbose stack at emitTwo (events.js:106:13)
14 verbose stack at ChildProcess.emit (events.js:191:7)
14 verbose stack at maybeClose (internal/child_process.js:852:16)
14 verbose stack at Process.ChildProcess._handle.onexit (internal/child_process.js:215:5)
15 verbose pkgid angular2-quickstart@1.0.0
16 verbose cwd /commonarea/vboxshared/www/backend/yii2/basic/web/kitchen
17 error Linux 3.19.0-15-generic
18 error argv "/home/justin/.nvm/versions/node/v6.3.1/bin/node" "/home/justin/.nvm/versions/node/v6.3.1/bin/npm" "start"
19 error node v6.3.1
20 error npm v3.10.3
21 error code ELIFECYCLE
22 error angular2-quickstart@1.0.0 start: `tsc && concurrently "npm run tsc:w" "npm run lite" `
22 error Exit status 2
23 error Failed at the angular2-quickstart@1.0.0 start script 'tsc && concurrently "npm run tsc:w" "npm run lite" '.
23 error Make sure you have the latest version of node.js and npm installed.
23 error If you do, this is most likely a problem with the angular2-quickstart package,
23 error not with npm itself.
23 error Tell the author that this fails on your system:
23 error tsc && concurrently "npm run tsc:w" "npm run lite"
23 error You can get information on how to open an issue for this project with:
23 error npm bugs angular2-quickstart
23 error Or if that isn't available, you can get their info via:
23 error npm owner ls angular2-quickstart
23 error There is likely additional logging output above.
24 verbose exit [ 1, true ]




Answer

do it like this remove the brackets []

import { bootstrap }    from '@angular/platform-browser-dynamic';
import { disableDeprecatedForms, provideForms } from '@angular/forms';
import { AppComponent } from './app.component';

bootstrap(AppComponent, [ 
    appRouterProviders,  
    disableDeprecatedForms(), 
    provideForms()
]);
Comments