使用 $state 参数 AngularJS 发送数据



我是 angular 新手,我不明白为什么我的数据没有从控制器发送到另一个带有状态参数的控制器,我的控制台中有"未定义"。你能帮我解决这个问题吗?

我的控制器 :

     .controller('RegistreCtrl', function ($scope, $stateParams,factotransaction,$state) {
            console.log("coucou");
            var mytoken = sessionStorage.getItem('token');
            factotransaction.send(mytoken).then(function(conf)
             {
                    console.log(conf);
                    $scope.datab = conf.data;
            })
            $scope.operation = function(id){

                $state.go('app.operation', { id: id });
                $state.params.id = id;

            }
    })

        .controller('OperationCtrl', function ($scope, $stateParams,factotransaction,$state) {

            var mytoken = sessionStorage.getItem('token');
            factotransaction.send(mytoken).then(function(conf){
                console.log(conf);
                conf.data.forEach(function(item){
                console.log($state.params.id);
                    if($state.params.id == item.id) {
                        $scope.item = item;
                        console.log(item);
                    }
                });
            });

我的应用.js :

  .state('app.operation', {
        url: '/operation',
        views: {
          'menuContent': {
            templateUrl: 'templates/operation.html',
            controller: 'OperationCtrl'
              }
          }
      })
;

我建议首先在路由本身中包含参数。

.state('albums.name',{
            //url:'',
            templateUrl:'views/tpls/player.tpl.html',
            controller:'playerCtrl as vm',
            params:{
                album:null,
            }
        });

关于如何将名为专辑的对象传递给路由的示例。

最新更新