TypeError:无法读取属性' go'未定义的

时间:2016-03-02 13:03:30

标签: javascript angularjs ionic-framework angularjs-scope angular-ui-router

//controller pour connection to API
.controller('LoginConnect', ['$scope','connecting','sendtoken','$state',
function($scope,connecting,sendtoken,$state){

  var token = [];
    $scope.user = {};
    var users = $scope.user;
    var cgtpage = false;

    $scope.connect = function (users,token,$state) {
      var log = $scope.user.login;
      var pass = $scope.user.password;
      var mydata = {};
      connecting.login(log,pass).then(function(result){
        var montoken = result.data.token;
         sessionStorage.setItem('token',montoken);
         console.log(montoken);
      });


      var mytoken = sessionStorage.getItem('token');

       sendtoken.send(mytoken).then(function(userdata){
            //email

            var email = userdata.data.login;
            sessionStorage.setItem('useremail',email);
            //prestation de services
            //vente de marchandises
            //période déclaration
            var declar_period = userdata.data.declaration_period;
            sessionStorage.setItem('userdeclar_period',declar_period);
            //Bénéficiaire ACCRE
            var accre = userdata.data.has_accre;
            sessionStorage.setItem('useraccre',accre);
            //Prénom
            var name = userdata.data.entrepreneur_firstname;
            sessionStorage.setItem('username',name);
            //Nom
            var lastname = userdata.data.entrepreneur_lastname;
            sessionStorage.setItem('userlastname',lastname);
            //Nom commercial
            var commercial_name = userdata.data.company_name;
            sessionStorage.setItem('userlcommercial',commercial_name);
            //siret
            var siret = userdata.data.company_siret;
            sessionStorage.setItem('usersiret',siret);
            //Date de création
            var creation = userdata.data.activity_start;
            sessionStorage.setItem('usercreation',creation);
            //Adresse
            var adresse = userdata.data.company_address;
            sessionStorage.setItem('useraddress',adresse);
            //code postal
            var cp = userdata.data.company_zipcode;
            sessionStorage.setItem('usercp',cp);
            //Ville
            var city = userdata.data.company_city;
            sessionStorage.setItem('usercity',city);
            //Pays
            var country = userdata.data.company_country;
            sessionStorage.setItem('usercountry',country);
            //télephone
            var phone = userdata.data.company_phone;
            sessionStorage.setItem('userphone',phone);

            if (name != null){
              cgtpage = true;
            };
            console.log(cgtpage);

            if(cgtpage === true){
              $state.go('app.home');
          };
       });
    };
  }
])

嗨,我没有成功更改页面,它总是说TypeError:无法读取属性' go'我认为因为我的函数中没有$ state而且我无法成功。你对我如何管理它有什么想法吗?

1 个答案:

答案 0 :(得分:5)

$state函数中删除connect参数,这会导致在$state控制器工厂函数中注入LoginConnect参数的存在。

$scope.connect = function (users,token) //<--removed $state