我正在將ng2-translate添加到項目中。當我添加TranslateService我得到:ng2-translate:TranslateService和Error:無法讀取未定義屬性'getOptional'(...)
Error: Cannot read property 'getOptional' of undefined(…)
我的系統配置的設置正確,但搜索我找不到任何可以幫助我弄清楚什麼是錯的小時後。
//angular
import {bootstrap} from "angular2/platform/browser";
import {Component,Inject,provide} from "angular2/core";
import {HTTP_PROVIDERS} from "angular2/http";
import {TranslateService,TranslateStaticLoader,TranslateLoader} from "ng2-translate/ng2-translate";
@Component({
selector: 'app',
directives: [TheApp],
template: '<the-app></the-app>'
})
class TT{
translate:TranslateService
constructor(@Inject(TranslateService) translate:TranslateService){
this.translate = translate;
....
}
....
}
bootstrap(TT,[
HTTP_PROVIDERS,
provide(TranslateLoader, {useClass: TranslateStaticLoader}),
TranslateService
]);
angular2.dev.js:353 TypeError: Cannot read property 'toString' of undefined angular2-polyfills.js:1243
Error: Cannot read property 'getOptional' of undefined(…)Zone.run @ angular2-polyfills.js:1243zoneBoundFn @ angular2-polyfills.js:1220lib$es6$promise$$internal$$tryCatch @ angular2-polyfills.js:468lib$es6$promise$$internal$$invokeCallback @ angular2-polyfills.js:480lib$es6$promise$$internal$$publish @ angular2-polyfills.js:451lib$es6$promise$$internal$$publishRejection @ angular2-polyfills.js:401(anonymous function) @ angular2-polyfills.js:123Zone.run @ angular2-polyfills.js:1243zoneBoundFn @ angular2-polyfills.js:1220lib$es6$promise$asap$$flush @ angular2-polyfills.js:262
<script src="es6-shim.min.js"></script>
<script src="es6-module-loader.js"></script>
<script src="system-polyfills.js"></script>
<script src="angular2-polyfills.js"></script>
<script src="system.src.js"></script>
<script src="Rx.js"></script>
<script src="angular2.dev.js"></script>
<script src="ng2-bootstrap.js"></script>
<script src="ng2-translate.js"></script>
<script src="router.js"></script>
<script src="http.js"></script>
<script>
System.transpiler = 'typescript';
System.config({
packages: {
ts: {
format: 'register',
defaultExtension: 'js'
}
},
map: {
moment: '/moment.js',
'ng2-translate/ng2-translate': '/ng2-translate.js'
}
});
System.import('ts/main')
.then(null, console.error.bind(console));
</script>
TypeError: Cannot read property 'getOptional' of undefined at runAppInitializers (localhost:8000/angular2.dev.js:12628:25) at PlatformRef.initApp (localhost:8000/angular2.dev.js:12603:21) at PlatformRef.application (localhost:8000/angular2.dev.js:12550:22) at Object.bootstrap (localhost:8000/angular2.dev.js:24805:64) at execute (localhost:8000/ts/main.js:118:23) at ensureEvaluated (localhost:8000/system.src.js:3197:26) at Object.execute (localhost:8000/system.src.js:3315:13) at doDynamicExecute (localhost:8000/system.src.js:708:25) at link (localhost:8000/system.src.js:910:20) at doLink (localhost:8000/system.src.js:562:7)
是否有可能您的導入無法正常工作? – Harangue
錯誤在哪裏發生?你可以添加錯誤消息/堆棧跟蹤? – Sasxa
添加錯誤 –