【发布时间】:2016-12-16 21:50:51
【问题描述】:
我正在将 ui-router2 与 angular2-rc-4 集成,但我得到了
错误:无效的提供者 - 只允许提供者和类型的实例,得到:[object Object]
以下是引导代码
从“ui-router-ng2”导入 {trace,UIROUTER_PROVIDERS,UIView,UIRouterConfig,Category,UIROUTER_DIRECTIVES}; 从“@angular/http”导入 {HTTP_PROVIDERS}; 从“@angular/core”导入{provide, PLATFORM_DIRECTIVES}; 从“@angular/common”导入{LocationStrategy、HashLocationStrategy、PathLocationStrategy、PlatformLocation}; 从'@angular/platform-browser'导入{BrowserPlatformLocation}; 导入'rxjs/add/operator/toPromise'; 导入'rxjs/add/operator/map'; 从“@angular/common”导入 { APP_BASE_HREF }; 从“@angular/forms”导入 { disableDeprecatedForms, provideForms }; 从“@angular/core”导入 { enableProdMode }; 从 '@angular/platform-browser-dynamic' 导入 { bootstrap }; 从'./app.routes'导入{ InitialStates }; 从'./app.component'导入{AppComponent}; 从“./_bootstrap/router.config”导入{MyUIRouterConfig}; if ('' === 'prod') { enableProdMode(); } trace.enable(Category.TRANSITION, Category.VIEWCONFIG); 引导程序(UIView,[ disableDeprecatedForms(), 提供表格(), 初始状态, { 提供:APP_BASE_HREF, 使用价值:'' }, 提供(LocationStrategy,{ useClass:HashLocationStrategy }), 提供(LocationStrategy,{ useClass:PathLocationStrategy }), 提供(平台位置,{ useClass:BrowserPlatformLocation }), ...UIROUTER_PROVIDERS, ...HTTP_PROVIDERS, 提供(UIRouterConfig,{ useClass:MyUIRouterConfig }), 提供(PLATFORM_DIRECTIVES,{useValue:[UIROUTER_DIRECTIVES],multi:true}) ]);以下是我的路由器配置。
import {UIRouter} from "ui-router-ng2";
import {InitialStates} from "../app.routes";
import {Injectable, Injector} from "@angular/core";
@Injectable()
export class MyUIRouterConfig {
constructor(private injector: Injector) {}
configure(uiRouter: UIRouter) {
// Register each state definition (from app.states.ts) with the StateRegistry
InitialStates.forEach(state => uiRouter.stateRegistry.register(state));
// Define a default behavior, for when the URL matched no routes
uiRouter.urlRouterProvider.otherwise(() => uiRouter.stateService.go("app", null, null) && null);
}
}
【问题讨论】:
标签: angular angular-ui-router angular2-routing