当我将angular2测试应用程序从beta-14转换为rc1时。我收到以下错误
ZoneDelegate.invoke @ angular2-polyfills.js:349 Error: Cannot read property 'toString' of undefined(…)
发出此错误的代码在这里
346 ZoneDelegate.prototype.invoke = function (targetZone, callback, applyThis, applyArgs, source) {
347 return this._invokeZS
348 ? this._invokeZS.onInvoke(this._invokeDlgt, this.zone, targetZone, callback, applyThis, applyArgs, source)
349 : callback.apply(applyThis, applyArgs);
350 };
导致错误的代码是main.ts
import {bootstrap} from '@angular/platform-browser-dynamic';
import {provide, ComponentRef} from '@angular/core';
import {ROUTER_PROVIDERS } from '@angular/router-deprecated';
// ,LocationStrategy, HashLocationStrategy
import { HTTP_PROVIDERS } from '@angular/http';
import 'rxjs/Rx';
import {APP_BASE_HREF} from '@angular/common'
import {AppComponent} from './appShell/app.component';
import {appInjector} from './login/auth.injector';
import {Authentication} from './login/auth.service';
bootstrap(AppComponent, [
ROUTER_PROVIDERS,
//provide(LocationStrategy, {useClass: HashLocationStrategy}),
provide(APP_BASE_HREF, {useValue: location.pathname}),
Authentication,
HTTP_PROVIDERS
])//.catch(err => console.error(err));
.then((appRef: ComponentRef<any>) => {
// store a reference to the application injector
appInjector(appRef.injector);
});
我使用了router-deprecated以实现向后兼容。此代码曾用于beta-14。
我使用了来自https://plnkr.co/edit/yRKhoOelf2uJ3yAsdIMm?p=preview的config.js。
LocationStrategy,HashLocationStrategy已被注释掉,因为它已不再包含在路由器中。是否被
取代provide(APP_BASE_HREF, {useValue: location.pathname}) ?
更重要的是,我能做些什么才能让它发挥作用?
答案 0 :(得分:2)
看起来config.js
是错误的。
我在the doc找到了官方插件,并没有显示任何错误。
http://plnkr.co/edit/wbRp2k67JiXbN2RFlaUc?p=preview
如上所述,您可以在LocationStrategy
中找到HashLocationStrategy
和@angular/common
。