Nativescript Angular2 路由提供者
Nativescript Angular2 Route Provider
我正在尝试使用 angular2 跟随 nativescript 的快速入门演示。当我来到路由器时,它开始出现故障。错误消息:没有 RouterOutletMap 的提供者!这是我的代码,
main.ts
#############
import {nativeScriptBootstrap} from "nativescript-angular/application";
import {ROUTER_DIRECTIVES,ROUTER_PROVIDERS} from '@angular/router-deprecated';
import {NS_ROUTER_DIRECTIVES, NS_ROUTER_PROVIDERS} from "nativescript-angular/router";
import {AppComponent} from "./app.component";
nativeScriptBootstrap(AppComponent, [ROUTER_PROVIDERS]);
和
app.component.ts
############
import {Component} from "@angular/core";
import {nativeScriptBootstrap} from "nativescript-angular/application";
import {RouteConfig, ROUTER_DIRECTIVES, ROUTER_PROVIDERS} from '@angular/router-deprecated';
import {NS_ROUTER_DIRECTIVES, NS_ROUTER_PROVIDERS} from "nativescript-angular/router";
import {FirstComponent} from "./first.component";
import {SecondComponent} from "./second.component";
@Component({
selector: 'navigation-test',
providers: [NS_ROUTER_PROVIDERS],
directives: [NS_ROUTER_DIRECTIVES],
template: `<page-router-outlet></page-router-outlet>`
})
@RouteConfig([
{ path: '/first', component: FirstComponent, name: 'First', useAsDefault: true },
{ path: '/second', component: SecondComponent, name: 'Second' },
])
export class AppComponent { }
作为 nativescript github 问题的解决方案 here
你应该从 "nativescript-angular/router-deprecated/ns-router-deprecated"
导入 NS_ROUTER_DIRECTIVES
, NS_ROUTER_PROVIDERS
像这样:
import {NS_ROUTER_DIRECTIVES, NS_ROUTER_PROVIDERS} from "nativescript-angular/router-deprecated/ns-router-deprecated";
及以下我删除了不必要的导入和提供程序以及...
main.ts
import {nativeScriptBootstrap} from "nativescript-angular/application";
import {AppComponent} from "./app.component";
nativeScriptBootstrap(AppComponent);
app.component.ts
import {Component} from "@angular/core";
import {RouteConfig} from '@angular/router-deprecated';
import {NS_ROUTER_DIRECTIVES, NS_ROUTER_PROVIDERS} from "nativescript-angular/router-deprecated/ns-router-deprecated";
import {FirstComponent} from "./first.component";
import {SecondComponent} from "./second.component";
@Component({
selector: 'navigation-test',
directives: [NS_ROUTER_DIRECTIVES],
providers: [NS_ROUTER_PROVIDERS],
template: `<page-router-outlet></page-router-outlet>`
})
@RouteConfig([
{ path: '/first', component: FirstComponent, name: 'First', useAsDefault: true },
{ path: '/second', component: SecondComponent, name: 'Second' },
])
export class AppComponent { }
我正在尝试使用 angular2 跟随 nativescript 的快速入门演示。当我来到路由器时,它开始出现故障。错误消息:没有 RouterOutletMap 的提供者!这是我的代码,
main.ts
#############
import {nativeScriptBootstrap} from "nativescript-angular/application";
import {ROUTER_DIRECTIVES,ROUTER_PROVIDERS} from '@angular/router-deprecated';
import {NS_ROUTER_DIRECTIVES, NS_ROUTER_PROVIDERS} from "nativescript-angular/router";
import {AppComponent} from "./app.component";
nativeScriptBootstrap(AppComponent, [ROUTER_PROVIDERS]);
和
app.component.ts
############
import {Component} from "@angular/core";
import {nativeScriptBootstrap} from "nativescript-angular/application";
import {RouteConfig, ROUTER_DIRECTIVES, ROUTER_PROVIDERS} from '@angular/router-deprecated';
import {NS_ROUTER_DIRECTIVES, NS_ROUTER_PROVIDERS} from "nativescript-angular/router";
import {FirstComponent} from "./first.component";
import {SecondComponent} from "./second.component";
@Component({
selector: 'navigation-test',
providers: [NS_ROUTER_PROVIDERS],
directives: [NS_ROUTER_DIRECTIVES],
template: `<page-router-outlet></page-router-outlet>`
})
@RouteConfig([
{ path: '/first', component: FirstComponent, name: 'First', useAsDefault: true },
{ path: '/second', component: SecondComponent, name: 'Second' },
])
export class AppComponent { }
作为 nativescript github 问题的解决方案 here
你应该从 "nativescript-angular/router-deprecated/ns-router-deprecated"
NS_ROUTER_DIRECTIVES
, NS_ROUTER_PROVIDERS
像这样:
import {NS_ROUTER_DIRECTIVES, NS_ROUTER_PROVIDERS} from "nativescript-angular/router-deprecated/ns-router-deprecated";
及以下我删除了不必要的导入和提供程序以及...
main.ts
import {nativeScriptBootstrap} from "nativescript-angular/application";
import {AppComponent} from "./app.component";
nativeScriptBootstrap(AppComponent);
app.component.ts
import {Component} from "@angular/core";
import {RouteConfig} from '@angular/router-deprecated';
import {NS_ROUTER_DIRECTIVES, NS_ROUTER_PROVIDERS} from "nativescript-angular/router-deprecated/ns-router-deprecated";
import {FirstComponent} from "./first.component";
import {SecondComponent} from "./second.component";
@Component({
selector: 'navigation-test',
directives: [NS_ROUTER_DIRECTIVES],
providers: [NS_ROUTER_PROVIDERS],
template: `<page-router-outlet></page-router-outlet>`
})
@RouteConfig([
{ path: '/first', component: FirstComponent, name: 'First', useAsDefault: true },
{ path: '/second', component: SecondComponent, name: 'Second' },
])
export class AppComponent { }