0
votes

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 };

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);
});

I used router-deprecated for backward compatibility. This code used to work with beta-14.

I used config.js from https://plnkr.co/edit/yRKhoOelf2uJ3yAsdIMm?p=preview.

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?

1
You can find LocationStrategy and HashLocationStrategy in @angular/common - Shuhei Kagawa

1 Answers

2
votes

It looks like the config.js is wrong.

I forked the official plunk found in the doc and it doesn't show any error.

http://plnkr.co/edit/wbRp2k67JiXbN2RFlaUc?p=preview

As commented above, you can find LocationStrategy and HashLocationStrategy in @angular/common.