角2 rc路由器angular2-polyfills.js:349错误 [英] angular 2 rc router angular2-polyfills.js:349 Error
问题描述
当我将我的angular2测试应用程序从beta-14转换为rc1时.我收到以下错误
When I converted my angular2 test app from beta-14 to rc1. I got the following error
ZoneDelegate.invoke @ angular2-polyfills.js:349 Error: Cannot read property 'toString' of undefined(…)
发出此错误的代码在这里
The code that issue this error is here
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
My code that caused the error is 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);
});
我使用了不推荐使用的路由器以实现向后兼容.该代码曾经与beta-14一起使用.
I used router-deprecated for backward compatibility. This code used to work with beta-14.
我从 https://plnkr.co/edit/yRKhoOelf2uJ3yAsdIMm?p=预览.
LocationStrategy,HashLocationStrategy已被注释掉,因为它已不再包含在路由器中.替换为
LocationStrategy, HashLocationStrategy is commented out because it's no longer included in router-deprecated. Is it replaced by
provide(APP_BASE_HREF, {useValue: location.pathname}) ?
更重要的是,我该怎么做才能使其正常工作?
And more important, What can I do to make it work?
推荐答案
看来config.js
是错误的.
我分叉了文档中发现的官方文件,但没有显示任何错误.
I forked the official plunk found in the doc and it doesn't show any error.
http://plnkr.co/edit/wbRp2k67JiXbN2RFlaUc?p=preview
如上所述,您可以在@angular/common
中找到LocationStrategy
和HashLocationStrategy
.
As commented above, you can find LocationStrategy
and HashLocationStrategy
in @angular/common
.
这篇关于角2 rc路由器angular2-polyfills.js:349错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!