我认为注入位置就像注入Http一样.然而,如果我在最后一行取消注释"公共位置:位置",我的应用程序会中断 - 页面无法呈现.据我所知,我有正确的import和providers数组:
import {Component} from 'angular2/core'; import { ROUTER_DIRECTIVES, ROUTER_PROVIDERS, RouteConfig, Location, LocationStrategy, HashLocationStrategy } from 'angular2/router'; import {TaskForm} from './task_form'; import {TaskList} from './task_list'; import {AboutUs} from './about_us'; @Component({ selector: 'task-app', templateUrl: 'app/task_app.html', providers: [ROUTER_PROVIDERS], directives: [TaskForm, TaskList, ROUTER_DIRECTIVES] }) @RouteConfig([ {path: '/', component: TaskApp, as: 'Home'}, {path: '/about_us', component: AboutUs, as: 'aboutUs'} ]) export class TaskApp { constructor(/*public location: Location*/) {
在我的index.html中,我有以下行:
在我的引导代码中,我有:
import {bootstrap} from 'angular2/platform/browser'; import {HTTP_PROVIDERS} from 'angular2/http'; import {provide} from 'angular2/core'; import { ROUTER_DIRECTIVES, ROUTER_PROVIDERS, RouteConfig, Location, LocationStrategy, HashLocationStrategy } from 'angular2/router'; import {TaskApp} from './task_app'; import {MyService} from './my_service' bootstrap(TaskApp, [HTTP_PROVIDERS, ROUTER_PROVIDERS, MyService, provide(LocationStrategy, {useClass: HashLocationStrategy})]);
不确定我是否遗漏了某些内容或当前版本是否已损坏.如果是第一种情况,我错过了什么?