2016-04-22 13 views
1

現在、多くの欲求不満の原因となっているエラーが発生しています。ここで私が実行されているものです:Angular2、RouteParamsが機能しない

  • ASP.NETコア1.0 RC1
  • Angular2、2.0.0-beta.15
  • 活字体、1.7.6.0

エラー:

Angular 2 is running in the development mode. Call enableProdMode() to enable the production mode. 
Attempting redirect to: /Design/0DEAC46A-7F58-49F9-B67E-2C187DFA49A7/ 
Navigated to http://localhost:5000/ 
EXCEPTION: Cannot resolve all parameters for 'RouteParams'(?). Make sure that all the parameters are decorated with Inject or have valid type annotations and that 'RouteParams' is decorated with Injectable. 
EXCEPTION: Cannot resolve all parameters for 'RouteParams'(?). Make sure that all the parameters are decorated with Inject or have valid type annotations and that 'RouteParams' is decorated with Injectable. 
EXCEPTION: Error: Uncaught (in promise): Cannot resolve all parameters for 'RouteParams'(?). Make sure that all the parameters are decorated with Inject or have valid type annotations and that 'RouteParams' is decorated with Injectable. 
EXCEPTION: Error: Uncaught (in promise): Cannot resolve all parameters for 'RouteParams'(?). Make sure that all the parameters are decorated with Inject or have valid type annotations and that 'RouteParams' is decorated with Injectable. 
STACKTRACE: 
Error: Uncaught (in promise): Cannot resolve all parameters for 'RouteParams'(?). Make sure that all the parameters are decorated with Inject or have valid type annotations and that 'RouteParams' is decorated with Injectable. 
    at resolvePromise (angular2-polyfills.js:602) 
    at angular2-polyfills.js:638 
    at ZoneDelegate.invokeTask (angular2-polyfills.js:423) 
    at Object.NgZoneImpl.inner.inner.fork.onInvokeTask (angular2.js:2118) 
    at ZoneDelegate.invokeTask (angular2-polyfills.js:422) 
    at Zone.runTask (angular2-polyfills.js:320) 
    at drainMicroTaskQueue (angular2-polyfills.js:541) 
    at XMLHttpRequest.ZoneTask.invoke (angular2-polyfills.js:493) 
Unhandled Promise rejection: Cannot resolve all parameters for 'RouteParams'(?). Make sure that all the parameters are decorated with Inject or have valid type annotations and that 'RouteParams' is decorated with Injectable. ; Zone: angular ; Task: Promise.then ; Value: NoAnnotationError {message: "Cannot resolve all parameters for 'RouteParams'(?)… that 'RouteParams' is decorated with Injectable.", stack: "Error: Cannot resolve all parameters for 'RoutePar…//localhost:5000/js/angular2/angular2.js:9448:46)"} 
Error: Uncaught (in promise): Cannot resolve all parameters for 'RouteParams'(?). Make sure that all the parameters are decorated with Inject or have valid type annotations and that 'RouteParams' is decorated with Injectable.(…) 
Unhandled Promise rejection: Cannot resolve all parameters for 'RouteParams'(?). Make sure that all the parameters are decorated with Inject or have valid type annotations and that 'RouteParams' is decorated with Injectable. ; Zone: <root> ; Task: Promise.then ; Value: NoAnnotationError {message: "Cannot resolve all parameters for 'RouteParams'(?)… that 'RouteParams' is decorated with Injectable.", stack: "Error: Cannot resolve all parameters for 'RoutePar…//localhost:5000/js/angular2/angular2.js:9448:46)"} 
Error: Uncaught (in promise): Cannot resolve all parameters for 'RouteParams'(?). Make sure that all the parameters are decorated with Inject or have valid type annotations and that 'RouteParams' is decorated with Injectable.(…) 

私は、Angular2という2つのサブクラスを持つ抽象基本クラスを持っています。それぞれにRouteParamsインスタンスを持つコンストラクタがあります。サブクラス1はうまく動作しますが、サブクラス2は上記のエラーメッセージでロードに失敗します。

RouteDefinitionは、実際にそうような経路で定義さAsyncRouteある:path: '/:appId/:customerId/'ここ

は、RouteParamsに反映しようとしたとき角度でスローエラーからのスクリーンキャプチャです。

enter image description here


基本クラス:

import {Component, OnInit} from "angular2/core"; 
import {RouteParams, Location} from "angular2/router"; 
import {CustomerService} from "../../shared/services/customer.service"; 

@Component({ 
    providers: [CustomerService] 
}) 

export abstract class BaseCustomerSelectorComponent implements OnInit { 
    protected params: RouteParams; 

    constructor(private customerService: CustomerService, 
       private routeParams: RouteParams, 
       private ngLocation: Location) { 
     this.params = routeParams; 
    } 

    ngOnInit() { 
     // omitted.. 
    } 
} 

は、サブクラス2:

import {Component} from "angular2/core"; 
import {RouteParams, Location} from "angular2/router"; 
import {BaseCustomerSelectorComponent} from "../../shared/components/base-customer-selector.component"; 
import {CustomerService} from "../../shared/services/customer.service"; 

@Component({ 
    selector: "customer-selector", 
    templateUrl: "app/shell/templates/customer-selector.html", 
    styleUrls: ["app/shell/styles/customer-selector.css"], 
    providers: [CustomerService, Settings, RouteParams] 
}) 

export class CustomerSelectorComponent extends BaseCustomerSelectorComponent { 
    constructor(customerService: CustomerService, 
       routeParams: RouteParams, 
       ngLocation: Location) { 
     super(customerService, routeParams, ngLocation); 
    } 
} 
+0

()(または代わりにのみ、ブートストラップ中)ROUTER_PROVIDERSのみルートコンポーネントに追加されていることを確認しますが、 'RouteParams'のみルータによって追加されたコンポーネントに注入することができる実際のコード – Gary

+0

を置くことができます。それ以外の場合、@ kemskyは言った。ルートコンポーネントに '** ROUTER_PROVIDERS'が** **追加されていることを確認してください(あるいは** bootstra()の** **のみ) –

+0

@GünterZöchbauer、あなたが正しいものであると答えてください。問題は2つのサブクラスコンポーネントの問題です。エラーはルータによって追加されません。 –

答えて

3

RouteParamsは、ルータによって追加されたコンポーネントでのみ注入できます。

あなたが Routerを注入し、そうでない場合@kemskyが言っ

constructor(private router:Router) { 
    router.subscribe(route => { 
     console.debug(this.router.currentInstruction.component.params); 
    }); 
    } 

をit`を購読することができ、他のコンポーネントで

+1

確かに "RouteParams"はルータによって追加されたコンポーネントにのみ注入できます。 "それが** Angular2 **文書に記載されたことを願っています。ありがとうございました! –

+0

ルータはまだ処理中です。私はいつでも変わるかもしれない事を文書化するのにあまりにも多くの時間を費やしたくないと思う。 –

+0

'RouteParams'を持たないコンポーネントからURLを解析するには、** Angular2 **の組み込み方法に精通していますか?私は 'URLSearchParams'を見ましたが、これはクエリ文字列のみたいです。 –

1

注射が継承されたインスタンスを使用する必要があり、プロバイダからRouteParamsを削除します。

よく、superコールを確認してください。パラメータの順序が間違っているようですが、設定は冗長です。

+0

それを試してみました。 –

+0

'ROUTER_PROVIDERS'を追加しようとしました – kemsky

+0

これも試してみました。明白な答えはありません。何とか基本クラスにバグがあると思いますか? –

関連する問題