2016-05-05 6 views
1

親ステートと子ステートがあります。 親状態は顧客の表示/編集に使用され、子状態は作成されます。親状態のパラメータを指定しない 、彼らは両方の負荷罰金:私は親状態にcustomerIdパラメータを追加し、私は子供の状態をロードし、最初の子状態の負荷をし、その後すぐにそれがスイッチanglejs ui-router親ステート、子ステート後にパラメータがロードされる

.state('crm.customer', { 
    url: 'crm/customers/', 
    templateUrl: 'src/modules/crm/views/customer.html', 
    controller: 'customersController' 
}) 
.state('crm.customer.create', { 
    url: 'crm/customers/create', 
    templateUrl: 'src/modules/crm/views/customer.html', 
    controller: 'customersController' 
}) 

親状態へ:

.state('crm.customer', { 
    url: 'crm/customers/:customerId', 
    templateUrl: 'src/modules/crm/views/customer.html', 
    controller: 'customersController' 
}) 
.state('crm.customer.create', { 
    url: 'crm/customers/create', 
    templateUrl: 'src/modules/crm/views/customer.html', 
    controller: 'customersController' 
}) 

子状態の読み込み後に親状態が読み込まれないようにするにはどうすればよいですか?

+1

これは、 '/ crm/customers/create'パスにアクセスしたときに両方のパスが一致するために発生します。この場合、 ':customerId'は' create'の値をとります。 'url: 'crm/customers /:customerId'' – iulian

+0

@iulianの代わりに' url:' crm/customers/{customerId:int} ''を試してみてください。 :D私はそれを受け入れることができるようにこれを答えとして追加してください! – orszaczky

答えて

1

これは、/crm/customers/createにアクセスすると、両方の状態のURLが一致するためです。この問題を解決するには、paramの型を定義します。 documentationによれば、中に中括弧を使用しているURL内のパラメータを定義するにはいくつかの方法があります:'/user/{id:int}'。あなたのケースでは

/crm/customers/createが唯一の子どもの状態と一致するように

.state('crm.customer', { 
    url: 'crm/customers/{customerId:int}', 
    templateUrl: 'src/modules/crm/views/customer.html', 
    controller: 'customersController' 
}) 

を使用しています。

関連する問題