2017-01-22 8 views
0

データを@objectに追加するには$ location.path()を使用し、フォームを提出するとurl.com/@objectですが、ページを再読み込みするときにページが見つからない場合:ページ、私はちょうどこのパラメータ@objectとurl.comをリロードする必要があります。どのようにすることが可能ですか?AngularJSのパスで別のページをリンクしていません

答えて

0

とデータオブジェクトが一致するものがrouteに定義されていないため、ページが見つからない理由が考えられます。

URL内からデータを渡したい場合は、経路を突き合わせながら、いくつかの方法があります。

  1. $routeParams

https://docs.angularjs.org/api/ngRoute/service/$routeParams

// Given: 
// URL: http://server.com/index.html#/Chapter/1/Section/2?search=moby 
// Route: /Chapter/:chapterId/Section/:sectionId 
// 
// Then 
$routeParams ==> {chapterId:'1', sectionId:'2', search:'moby'} 
  • $location.hash()
  • https://docs.angularjs.org/api/ng/service/$location#hash

    // given URL http://example.com/#/some/path?foo=bar&baz=xoxo#hashValue 
    var hash = $location.hash(); 
    // => "hashValue" 
    

    https://docs.angularjs.org/api/ng/service/$location#search

    // given URL http://example.com/#/some/path?foo=bar&baz=xoxo 
    var searchObject = $location.search(); 
    // => {foo: 'bar', baz: 'xoxo'} 
    
    // set foo to 'yipee' 
    $location.search('foo', 'yipee'); 
    // $location.search() => {foo: 'yipee', baz: 'xoxo'} 
    

  • $location.search()
  • しかし、それはデータを格納するユーザ Serviceに良好であってもよいです。 AngularJSでは、サービスは Singletonです。これは、それらが一度インスタンス化されたことを意味し、 stateおよび/または dataを格納するのに最適です。

    More info on how to use services.

    ご質問があれば私に知らせてください。

    関連する問題