【发布时间】:2016-05-07 01:38:06
【问题描述】:
当我将我的 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}) ?
更重要的是,我该怎么做才能让它发挥作用?
【问题讨论】:
-
你可以在
@angular/common找到LocationStrategy和HashLocationStrategy