angular 2 rc 路由器 angular2-polyfills.js:349 错误
angular 2 rc router angular2-polyfills.js:349 Error
当我将我的 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);
});
为了向后兼容,我使用了已弃用的路由器。此代码用于使用 beta-14。
我使用了 https://plnkr.co/edit/yRKhoOelf2uJ3yAsdIMm?p=preview 中的 config.js。
LocationStrategy、HashLocationStrategy 被注释掉,因为它不再包含在 router-deprecated 中。是不是换成了
provide(APP_BASE_HREF, {useValue: location.pathname}) ?
更重要的是,我该怎么做才能让它发挥作用?
看起来 config.js
是错误的。
我 fork 了在 the doc 中找到的官方 plunk,它没有显示任何错误。
http://plnkr.co/edit/wbRp2k67JiXbN2RFlaUc?p=preview
如上所述,您可以在 @angular/common
中找到 LocationStrategy
和 HashLocationStrategy
。
当我将我的 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);
});
为了向后兼容,我使用了已弃用的路由器。此代码用于使用 beta-14。
我使用了 https://plnkr.co/edit/yRKhoOelf2uJ3yAsdIMm?p=preview 中的 config.js。
LocationStrategy、HashLocationStrategy 被注释掉,因为它不再包含在 router-deprecated 中。是不是换成了
provide(APP_BASE_HREF, {useValue: location.pathname}) ?
更重要的是,我该怎么做才能让它发挥作用?
看起来 config.js
是错误的。
我 fork 了在 the doc 中找到的官方 plunk,它没有显示任何错误。
http://plnkr.co/edit/wbRp2k67JiXbN2RFlaUc?p=preview
如上所述,您可以在 @angular/common
中找到 LocationStrategy
和 HashLocationStrategy
。