在bootstrap()中使用[disableDeprecatedForms(),provideForms()]时,Angular2表单编译错误

时间:2016-08-02 16:25:08

标签: angularjs angular angular2-forms

我正在尝试使用AngularJS 2构建一个简单的表单,遵循快速入门指南(https://angular.io/docs/ts/latest/guide/forms.html)中的示例。
当我按照bootstrap()函数中的建议禁用旧表单模块并启用新表单模块时,我收到编译错误。

我对AngularJs很新。任何帮助表示赞赏。详情如下:

在向引导函数添加“[disableDeprecatedForms(),provideForms()]”时,会引发编译错误。

以下是main.ts文件中的代码。

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 ] );
*/

如果我在main.ts中有上面的代码时,“npm start”正在转换,我得到以下编译错误。

如果我使用注释中显示的bootstrap()调用,它会编译没有错误,但会发出警告“*看起来你正在使用旧的表单模块....”

[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.

如果我用main.ts中的这段代码启动“npm start”,npm只是拒绝启动并抛出ERR!。以下是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 ]

1 个答案:

答案 0 :(得分:1)

这样做删除括号[]

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

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