UiRouter - stateparames为null

时间:2015-11-09 11:05:32

标签: angularjs

在控制器中我得到$stateParams.foo未定义

MoviesApp.config(function($stateProvider, $urlRouterProvider) {

    $urlRouterProvider.otherwise('/home');

    $stateProvider
        .state('home', {
            url: '/home',
            templateUrl: '/Partial/home.html'
        })
        .state('movieDetails', {
            url: '/allPlaces',
            views: {
                '': {
                  templateUrl: '/Partial/movieDetails.html',
                  controller: 'movieDetailsCtrl'
                }
           }
     });
});

   /*.state('home', {
        url: '/:foo?bar',
        views: {
            '': {
               templateUrl: 'tpl.home.html',
               controller: 'MainRootCtrl'

    },*/

MoviesApp.controller('movieDetailsCtrl', function($scope, $state,$stateParams) {
      //..
      var foo = $stateParams.foo; //getting fooVal
      var bar = $stateParams.bar; //getting barVal
      //..
      $scope.state = $state.current
      $scope.params = $stateParams; 
})

2 个答案:

答案 0 :(得分:0)

MoviesApp.controller('movieDetailsCtrl', ['$scope', '$state', '$stateParams'], function($scope, $state, $stateParams) { 
  var foo = $stateParams.foo;
  var bar = $stateParams.bar;
  $scope.state = $state.current
  $scope.params = $stateParams; 
})

试试这个,你可能忘了向控制器注入一个$ stateParams

答案 1 :(得分:0)

您需要像这样设置您的州:

QTextCodec *codec = QTextCodec::codecForName("Windows-1251");
if(codec == 0)
{
    QTextStream(stdout) << "No codec was found" << endl;
}
QTextDecoder *decoder = codec->makeDecoder();

QString inp_fileName = QString(decoder->toUnicode(argv[1]));
................
QFile inp_file(inp_fileName);
if(!inp_file.open(inp_file.ReadOnly))
{
    QTextStream(stdout) << "Could not open file for reading.\n" << inp_file.errorString() << endl;
    return -3;
}

然后通过使用:ng-sref

进入该状态
.state('home', { 
  url: '/:foo/:bar', 
  views: { 
    '': {templateUrl: 'tpl.home.html', controller: 'MainRootCtrl'}
  }
}