我见过很多人遇到这个问题,并提出了与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)
当区域中有2个副本在同一位置运行时,会发生这种情况。以前是system-polyfill。
当同时包含zone.js时,我遇到了相同的问题。当两个区域都监视所有的promise调用时,它们将相互反弹并导致堆栈溢出。
angular-polyfill始终包含ng自己的区域实现。zone.js不应单独加载。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句