我已经看到很多人遇到这个问题,并提供了与angular2-polyfills.js相关的解决方案。我已将此文件包含在我的webpack中,但是:
entry: {
'angular2': [
'rxjs',
'zone.js',
'reflect-metadata',
'angular2/common',
'angular2/core',
'angular2/router',
'angular2/http',
'angular2/bundles/angular2-polyfills'
],
'app': [
'./src/app/bootstrap'
]
}
尽管如此,我在尝试加载根组件时遇到以下错误:
Cannot resolve all parameters for 'ResolvedMetadataCache'(?, ?). Make sure that all the parameters are decorated with Inject or have valid type annotations and that 'ResolvedMetadataCache' is decorated with Injectable.
Uncaught TypeError: Cannot read property 'getOptional' of undefined
来自dom_element_schema_registry:43
。我做错了什么?
以下是相关的组件文件。
import {Component} from 'angular2/core';
import {MapComponent} from './map/map.component';
declare var window: any;
var $ = require('jquery');
window.$ = $;
window.jQuery = $;
@Component({
selector: 'app',
template: require('./app.component.jade'),
styles: [],
directives: [MapComponent]
})
export class AppComponent {}
修改 这可能与我使用jade-loader有关;当我切换到需要原始HTML文件时,我得到一个不同的错误:
dom_element_schema_registry.ts:43 Uncaught EXCEPTION: Error during instantiation of Token Promise<ComponentRef>!.
ORIGINAL EXCEPTION: RangeError: Maximum call stack size exceeded
ORIGINAL STACKTRACE:
RangeError: Maximum call stack size exceeded
at ZoneDelegate.scheduleTask (http://localhost:3000/angular2.bundle.js:20262:28)
at Zone.scheduleMicroTask (http://localhost:3000/angular2.bundle.js:20184:41)
at scheduleResolveOrReject (http://localhost:3000/angular2.bundle.js:20480:16)
at ZoneAwarePromise.then [as __zone_symbol__then] (http://localhost:3000/angular2.bundle.js:20555:19)
at scheduleQueueDrain (http://localhost:3000/angular2.bundle.js:20361:63)
at scheduleMicroTask (http://localhost:3000/angular2.bundle.js:20369:11)
at ZoneDelegate.scheduleTask (http://localhost:3000/angular2.bundle.js:20253:23)
at Zone.scheduleMicroTask (http://localhost:3000/angular2.bundle.js:20184:41)
at scheduleResolveOrReject (http://localhost:3000/angular2.bundle.js:20480:16)
at ZoneAwarePromise.then [as __zone_symbol__then] (http://localhost:3000/angular2.bundle.js:20555:19)
答案 0 :(得分:1)
当2个区域副本在同一个地方运行时会发生这种情况。以前是system-polyfill。
在同时包含zone.js时遇到同样的问题。当2区域都监视所有promise呼叫时,它们将互相反弹并导致堆栈溢出。
angular-polyfill始终包含ng自己的区域实现。 zone.js不应单独加载。