我目前在应用组件级别设置HTTP_PROVIDERS。我通过./node_modules/.bin/ngc运行编译器时看到错误。
运行编译器时出现完整错误
Error: Error at /Users/girishnanda/Documents/offlinecompiler/src/app.component.ngfactory.ts:47:33: Module '"/Users/girishnanda/Documents/offlinecompiler/node_modules/@angular/http/http"' has no exported member 'HTTP_PROVIDERS'.
Error at /Users/girishnanda/Documents/offlinecompiler/src/app.component.ngfactory.ts:51:38: Module '"/Users/girishnanda/Documents/offlinecompiler/node_modules/@angular/http/http"' has no exported member 'HTTP_PROVIDERS'.
Error at /Users/girishnanda/Documents/offlinecompiler/src/app.component.ngfactory.ts:53:77: Cannot use 'new' with an expression whose type lacks a call or construct signature.
at check (/Users/girishnanda/Documents/offlinecompiler/node_modules/@angular/compiler-cli/tsc.js:32:15)
at Tsc.typeCheck (/Users/girishnanda/Documents/offlinecompiler/node_modules/@angular/compiler-cli/tsc.js:67:9)
at /Users/girishnanda/Documents/offlinecompiler/node_modules/@angular/compiler-cli/main.js:39:23
at process._tickCallback (node.js:406:9)
at Function.Module.runMain (module.js:449:11)
at startup (node.js:141:18)
at node.js:933:3
Compilation failed
我正在设置HTTP_PROVIDERS
的应用程序组件import {Component} from '@angular/core';
import {HTTP_PROVIDERS} from '@angular/http';
@Component({
selector: 'app',
template: `test
`,
providers: [HTTP_PROVIDERS]
})
export class AppComponent {
constructor() { }
}
Compiler,Compile-cli,typescript和@ angular / http的版本
"@angular/compiler": "2.0.0-rc.1",
"@angular/compiler-cli": "0.2.0",
"@angular/http": "2.0.0-rc.1",
"typescript": "^1.9.0-dev.20160605-1.0"
Tsconfig.json
{
"compilerOptions": {
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"target": "es5",
"module": "commonjs",
"moduleResolution": "node",
"removeComments": true,
"sourceMap": true,
"outDir": "built",
"noImplicitAny": false
},
"exclude": [
"typings/main.d.ts",
"typings/main",
"node_modules"
]
}
Typings.json
{
"globalDependencies": {
"core-js": "registry:dt/core-js#0.0.0+20160317120654",
"jasmine": "registry:dt/jasmine#2.2.0+20160505161446",
"node": "registry:dt/node#4.0.0+20160509154515"
}
}
如果我不包含HTTP_PROVIDERS,则编译成功运行且没有错误。对我可能需要更改以便我可以使用HTTP_PROVIDERS进行编译的任何指导都会有所帮助。
回复尝试在bootstrap上添加提供程序的注释。 这是我的主要内容。我还没弄清楚如何添加其他提供商。这是脱机编译器的基本示例。
import {coreBootstrap, ReflectiveInjector, enableProdMode} from '@angular/core';
import {browserPlatform, BROWSER_APP_COMMON_PROVIDERS, BROWSER_APP_STATIC_PROVIDERS} from '@angular/platform-browser';
import {AppComponentNgFactory} from './app.component.ngfactory';
import {AppComponent} from './app.component';
enableProdMode();
const appInjector =
ReflectiveInjector
.resolveAndCreate(BROWSER_APP_COMMON_PROVIDERS, browserPlatform().injector);
coreBootstrap(appInjector, AppComponentNgFactory);
答案 0 :(得分:0)
这对我有用。
const appInjector =
ReflectiveInjector
.resolveAndCreate([
BROWSER_APP_PROVIDERS,
HTTP_PROVIDERS
], browserPlatform().injector);
coreBootstrap(someComponentNgFactory, appInjector);