Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
343 views
in Technique[技术] by (71.8m points)

angular - Location and HashLocationStrategy stopped working in beta.16

Error message

VM556 angular2-polyfills.js:349Error: Token must be defined!(…)

or

error TS2305: Module '"/node_modules/angular2/router"' has no exported member 'LocationStrategy'.
error TS2305: Module '"/node_modules/angular2/router"' has no exported member 'HashLocationStrategy'.
error TS2305: Module '"/node_modules/angular2/router"' has no exported member 'Location'.

How to fix

Question&Answers:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

update >= rc.5

@NgModule({
  providers: [{ provide: LocationStrategy, useClass: HashLocationStrategy}]
})
export class AppModule {}

update >= rc.0

import {  
  PlatformLocation,  
  Location,  
  LocationStrategy,  
  HashLocationStrategy,  
  PathLocationStrategy,  
  APP_BASE_HREF}  
from '@angular/common';  

import {BrowserPlatformLocation} from   '@angular/platform-browser';

original

Change

import {ROUTER_PROVIDERS, LocationStrategy, HashLocationStrategy} from 'angular2/router';

to

import {ROUTER_PROVIDERS} from 'angular2/router';
import {LocationStrategy, HashLocationStrategy} from 'angular2/platform/common';

See also
- https://github.com/angular/angular/issues/8229

Full list of moved exports:
- https://github.com/angular/angular/pull/8230/files

import {  
  PlatformLocation,  
  Location,  
  LocationStrategy,  
  HashLocationStrategy,  
  PathLocationStrategy,  
  APP_BASE_HREF}  
from 'angular2/platform/common';  

import {BrowserPlatformLocation} from   'angular2/src/platform/browser/location/browser_platform_location';

Another error that's commonly caused by this change is

location.createComponent is not a function


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...