LoginSignup
19
21

More than 5 years have passed since last update.

$state.goでのパラメータの引き渡し方

Posted at

AngularJSを使っている時にあるURLから異なるURLへパラメータを渡しつつ遷移する時に$state.goを使うと思います。
しかし、私の場合以下の様にコードを書いてみても上手くパラメータが引き渡せませんでした。

main.controller.js
$state.go('hoge', { parameter: 1 });
hoge.js
$stateProvider
  .state('hoge', {
    url: '/hoge',
    templateUrl: 'app/hoge/hoge.html',
    controller: 'HogeCtrl'
  });

で、アレコレ考えた結果以下の様にhoge.jsを変更したら引き渡せました。

hoge.js
$stateProvider
  .state('hoge', {
    url: '/hoge',
    templateUrl: 'app/hoge/hoge.html',
    controller: 'HogeCtrl',
    params: {'parameter' : null}
  });

このコード内でnullをパラメータに入れていますが、nullを省いてみると動きませんでした・・・
これについてはどこにも参考になる文献がありませんでしたので、ご存じの方はコメント欄等でお教え頂けると幸いです。

19
21
3

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
19
21