2016-08-23 10 views
0

URLパラメータを使用してanglejsアプリケーション内の別のビューに移動しようとしています。 $stateProvider角度変更ビューURLパラメータ

<a ui-sref="Devices({resourceView: 'deviceGroupView', explorerView: 'table', type: 'Device', uuid: treeCurrentNode.uuid})">{{treeCurrentNode.displayName}}</a> 

を使用して

$location.path('/devices').search({resourceView: 'deviceDetailsView'}) 
       .search({explorerView: 'table'}).search({type: 'Device'}).search({uuid: uuid}); 

そして、このような何か私の状態プロバイダのコードは次のようになります:

.state('Devices', { 
    url: "/devices", 
    params: { 
     resourceView: null, 
     explorerView: null, 
     type: null, 
     uuid: null 
    }, 
    templateUrl: "app/main/devices/module/views/devices.html", 
    controller: "DevicesExtendedCtrl", 
    reloadOnSearch: false, 
私はこの

<a href="" ng-click="goToDevice(treeCurrentNode.uuid)">{{treeCurrentNode.displayName}}</a> 

jsのようなものを試してみました

$state.go('Devices', {resourceView: 'deviceDetailsView', explorerView: 'table', type: 'Device', uuid: uuid}) 

をしかし、パラメータがURLに追加されていない:Oこの

<a href="" ng-click="go(treeCurrentNode.uuid)">{{treeCurrentNode.displayName}}</a> 

jsのよう$state.goを使用して$stateProviderを使用してみました。タイプとUUIDを

$location.path('/devices') 

はデフォルトでそこにresourceViewとexplorerViewパラメータを持っていますが、ありません:URLは私は私はこのようなパラメータを追加しようとしていないときに取られています。

答えて

0

にあなたが見つけることができる

詳細は、私が$location.search('uuid', uuid)にそれを変更し、それは、stateProviderを修正する必要が働いていません。

0

stateproviderコードを次のように変更してください。動作するかどうかを確認してください。それは私の仕事だった。

.state('Devices', { 
    url: "/devices/:resourceView/:explorerView/:type/:uuid", 
    params: { 
     resourceView: null, 
     explorerView: null, 
     type: null, 
     uuid: null 
    }, 
    templateUrl: "app/main/devices/module/views/devices.html", 
    controller: "DevicesExtendedCtrl", 
    reloadOnSearch: false, 
+0

これは近いです。パラメータを追加しようとしなかったときに指し示されている既定のURLは、既にresourceViewとexplorerViewがパラメータとして追加されているということに触れておきます。このようなコードを変更すると、パラメータとしてresourceViewとexplorerViewがありますが、パラメータの前にコンテキストパスにtypeとuuidが追加されます – gary69

0

私はあなたの$ stateProviderにurlプロパティを定義する必要がありますので、あなたはUI-ルータを使用していることを前提としています。これは次のようになります。

$stateProvider 
    .state('contacts.detail', { 
     url: "/contacts/:contactId", 
     templateUrl: 'contacts.detail.html', 
     controller: function ($stateParams) { 
      // If we got here from a url of /contacts/42 
      expect($stateParams).toBe({contactId: "42"}); 
     } 
    }) 

この例では、contactId paramaterを定義しました。 /contact/123はあなたのURLと一致する必要があります。

ui-routerを使用してパラメータを定義するときは、$ stateParams.contactIdを使用してパラメータを定義できます。私は間違っ$location.search()を呼んでいたhttps://github.com/angular-ui/ui-router/wiki/URL-Routing#url-parameters

関連する問題