Cannot read property 'email' of undefined











up vote
0
down vote

favorite












I am building an application in AngularJS and CodeIgniter - I have a problem with the execution of a certain code:



controllersAdmin.controller('login', function( $scope, $http, store){

$scope.formSubmit = function (user){

$http({
method: 'POST', url: 'api/admin/users/login/' ,
data: {
email : user.email,
password : user.password
}}
).then(function ( data ){

$scope.submit = true;
$scope.error = data.error;

if ( !data.error )
{
store.set('token', data.token)
}


},function (error){
console.log('Blad we wczytywaniu danych');
});
};

console.log( store.get( 'token' ) );

});


Below is my PHP login function:



public function login()
{
$email = $this->input->post('email');
$password = $this->input->post('password');
$password = crypt( $password, config_item('encryption_key'));

$login = $this->Users_model->login($email, $password);

if ( !$login ) {

$output['error'] = 'Błędne hasło lub email';

}
else
{
$token = $this->jwt->encode( array(
'userId' => $login ->id,
'user' => $login ->user,
'email' => $login ->email,
'role' => $login ->role
), config_item('encryption_key'));
$output['token'] = $token;
}
echo json_encode($output);
}


The message he receives in the console is:



TypeError: Cannot read property 'email' of undefined
at ChildScope.$scope.formSubmit (controllers-admin.js:549)



Line 549: email : user.email,










share|improve this question


























    up vote
    0
    down vote

    favorite












    I am building an application in AngularJS and CodeIgniter - I have a problem with the execution of a certain code:



    controllersAdmin.controller('login', function( $scope, $http, store){

    $scope.formSubmit = function (user){

    $http({
    method: 'POST', url: 'api/admin/users/login/' ,
    data: {
    email : user.email,
    password : user.password
    }}
    ).then(function ( data ){

    $scope.submit = true;
    $scope.error = data.error;

    if ( !data.error )
    {
    store.set('token', data.token)
    }


    },function (error){
    console.log('Blad we wczytywaniu danych');
    });
    };

    console.log( store.get( 'token' ) );

    });


    Below is my PHP login function:



    public function login()
    {
    $email = $this->input->post('email');
    $password = $this->input->post('password');
    $password = crypt( $password, config_item('encryption_key'));

    $login = $this->Users_model->login($email, $password);

    if ( !$login ) {

    $output['error'] = 'Błędne hasło lub email';

    }
    else
    {
    $token = $this->jwt->encode( array(
    'userId' => $login ->id,
    'user' => $login ->user,
    'email' => $login ->email,
    'role' => $login ->role
    ), config_item('encryption_key'));
    $output['token'] = $token;
    }
    echo json_encode($output);
    }


    The message he receives in the console is:



    TypeError: Cannot read property 'email' of undefined
    at ChildScope.$scope.formSubmit (controllers-admin.js:549)



    Line 549: email : user.email,










    share|improve this question
























      up vote
      0
      down vote

      favorite









      up vote
      0
      down vote

      favorite











      I am building an application in AngularJS and CodeIgniter - I have a problem with the execution of a certain code:



      controllersAdmin.controller('login', function( $scope, $http, store){

      $scope.formSubmit = function (user){

      $http({
      method: 'POST', url: 'api/admin/users/login/' ,
      data: {
      email : user.email,
      password : user.password
      }}
      ).then(function ( data ){

      $scope.submit = true;
      $scope.error = data.error;

      if ( !data.error )
      {
      store.set('token', data.token)
      }


      },function (error){
      console.log('Blad we wczytywaniu danych');
      });
      };

      console.log( store.get( 'token' ) );

      });


      Below is my PHP login function:



      public function login()
      {
      $email = $this->input->post('email');
      $password = $this->input->post('password');
      $password = crypt( $password, config_item('encryption_key'));

      $login = $this->Users_model->login($email, $password);

      if ( !$login ) {

      $output['error'] = 'Błędne hasło lub email';

      }
      else
      {
      $token = $this->jwt->encode( array(
      'userId' => $login ->id,
      'user' => $login ->user,
      'email' => $login ->email,
      'role' => $login ->role
      ), config_item('encryption_key'));
      $output['token'] = $token;
      }
      echo json_encode($output);
      }


      The message he receives in the console is:



      TypeError: Cannot read property 'email' of undefined
      at ChildScope.$scope.formSubmit (controllers-admin.js:549)



      Line 549: email : user.email,










      share|improve this question













      I am building an application in AngularJS and CodeIgniter - I have a problem with the execution of a certain code:



      controllersAdmin.controller('login', function( $scope, $http, store){

      $scope.formSubmit = function (user){

      $http({
      method: 'POST', url: 'api/admin/users/login/' ,
      data: {
      email : user.email,
      password : user.password
      }}
      ).then(function ( data ){

      $scope.submit = true;
      $scope.error = data.error;

      if ( !data.error )
      {
      store.set('token', data.token)
      }


      },function (error){
      console.log('Blad we wczytywaniu danych');
      });
      };

      console.log( store.get( 'token' ) );

      });


      Below is my PHP login function:



      public function login()
      {
      $email = $this->input->post('email');
      $password = $this->input->post('password');
      $password = crypt( $password, config_item('encryption_key'));

      $login = $this->Users_model->login($email, $password);

      if ( !$login ) {

      $output['error'] = 'Błędne hasło lub email';

      }
      else
      {
      $token = $this->jwt->encode( array(
      'userId' => $login ->id,
      'user' => $login ->user,
      'email' => $login ->email,
      'role' => $login ->role
      ), config_item('encryption_key'));
      $output['token'] = $token;
      }
      echo json_encode($output);
      }


      The message he receives in the console is:



      TypeError: Cannot read property 'email' of undefined
      at ChildScope.$scope.formSubmit (controllers-admin.js:549)



      Line 549: email : user.email,







      angularjs codeigniter-3






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked 2 days ago









      danko12

      497




      497
























          1 Answer
          1






          active

          oldest

          votes

















          up vote
          1
          down vote



          accepted










          Cannot read property 'email' of undefined - Maybe you are wrong with passing your password and email from ng-model user



          Try something like this :



          <h2 class="form-signin-heading">Please sign in</h2>
          <div class="form-group">
          <input class="form-control" placeholder="Username" ng-model="user.email">
          </div>
          <div class="form-group">
          <input class="form-control" placeholder="Password" type="password" ng-model="user.password" >
          </div>
          <button class="btn btn-lg btn-success btn-block" ng-click="formSubmit(user)">Login</button>


          JS:



             $scope.formSubmit = function (user){
          console.log(user)
          console.log("email : ", user.email )
          console.log("password: ", user.password)
          }


          In my code i can easly console email and user password.



          Here is plunker: http://plnkr.co/edit/AeUARBrQRGHHYvVM6pd2?p=preview






          share|improve this answer








          New contributor




          BartoszTermena is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
          Check out our Code of Conduct.


















          • The addition of ng-click has helped.
            – danko12
            2 days ago











          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














           

          draft saved


          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53239139%2fcannot-read-property-email-of-undefined%23new-answer', 'question_page');
          }
          );

          Post as a guest
































          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes








          up vote
          1
          down vote



          accepted










          Cannot read property 'email' of undefined - Maybe you are wrong with passing your password and email from ng-model user



          Try something like this :



          <h2 class="form-signin-heading">Please sign in</h2>
          <div class="form-group">
          <input class="form-control" placeholder="Username" ng-model="user.email">
          </div>
          <div class="form-group">
          <input class="form-control" placeholder="Password" type="password" ng-model="user.password" >
          </div>
          <button class="btn btn-lg btn-success btn-block" ng-click="formSubmit(user)">Login</button>


          JS:



             $scope.formSubmit = function (user){
          console.log(user)
          console.log("email : ", user.email )
          console.log("password: ", user.password)
          }


          In my code i can easly console email and user password.



          Here is plunker: http://plnkr.co/edit/AeUARBrQRGHHYvVM6pd2?p=preview






          share|improve this answer








          New contributor




          BartoszTermena is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
          Check out our Code of Conduct.


















          • The addition of ng-click has helped.
            – danko12
            2 days ago















          up vote
          1
          down vote



          accepted










          Cannot read property 'email' of undefined - Maybe you are wrong with passing your password and email from ng-model user



          Try something like this :



          <h2 class="form-signin-heading">Please sign in</h2>
          <div class="form-group">
          <input class="form-control" placeholder="Username" ng-model="user.email">
          </div>
          <div class="form-group">
          <input class="form-control" placeholder="Password" type="password" ng-model="user.password" >
          </div>
          <button class="btn btn-lg btn-success btn-block" ng-click="formSubmit(user)">Login</button>


          JS:



             $scope.formSubmit = function (user){
          console.log(user)
          console.log("email : ", user.email )
          console.log("password: ", user.password)
          }


          In my code i can easly console email and user password.



          Here is plunker: http://plnkr.co/edit/AeUARBrQRGHHYvVM6pd2?p=preview






          share|improve this answer








          New contributor




          BartoszTermena is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
          Check out our Code of Conduct.


















          • The addition of ng-click has helped.
            – danko12
            2 days ago













          up vote
          1
          down vote



          accepted







          up vote
          1
          down vote



          accepted






          Cannot read property 'email' of undefined - Maybe you are wrong with passing your password and email from ng-model user



          Try something like this :



          <h2 class="form-signin-heading">Please sign in</h2>
          <div class="form-group">
          <input class="form-control" placeholder="Username" ng-model="user.email">
          </div>
          <div class="form-group">
          <input class="form-control" placeholder="Password" type="password" ng-model="user.password" >
          </div>
          <button class="btn btn-lg btn-success btn-block" ng-click="formSubmit(user)">Login</button>


          JS:



             $scope.formSubmit = function (user){
          console.log(user)
          console.log("email : ", user.email )
          console.log("password: ", user.password)
          }


          In my code i can easly console email and user password.



          Here is plunker: http://plnkr.co/edit/AeUARBrQRGHHYvVM6pd2?p=preview






          share|improve this answer








          New contributor




          BartoszTermena is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
          Check out our Code of Conduct.









          Cannot read property 'email' of undefined - Maybe you are wrong with passing your password and email from ng-model user



          Try something like this :



          <h2 class="form-signin-heading">Please sign in</h2>
          <div class="form-group">
          <input class="form-control" placeholder="Username" ng-model="user.email">
          </div>
          <div class="form-group">
          <input class="form-control" placeholder="Password" type="password" ng-model="user.password" >
          </div>
          <button class="btn btn-lg btn-success btn-block" ng-click="formSubmit(user)">Login</button>


          JS:



             $scope.formSubmit = function (user){
          console.log(user)
          console.log("email : ", user.email )
          console.log("password: ", user.password)
          }


          In my code i can easly console email and user password.



          Here is plunker: http://plnkr.co/edit/AeUARBrQRGHHYvVM6pd2?p=preview







          share|improve this answer








          New contributor




          BartoszTermena is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
          Check out our Code of Conduct.









          share|improve this answer



          share|improve this answer






          New contributor




          BartoszTermena is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
          Check out our Code of Conduct.









          answered 2 days ago









          BartoszTermena

          1114




          1114




          New contributor




          BartoszTermena is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
          Check out our Code of Conduct.





          New contributor





          BartoszTermena is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
          Check out our Code of Conduct.






          BartoszTermena is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
          Check out our Code of Conduct.












          • The addition of ng-click has helped.
            – danko12
            2 days ago


















          • The addition of ng-click has helped.
            – danko12
            2 days ago
















          The addition of ng-click has helped.
          – danko12
          2 days ago




          The addition of ng-click has helped.
          – danko12
          2 days ago


















           

          draft saved


          draft discarded



















































           


          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53239139%2fcannot-read-property-email-of-undefined%23new-answer', 'question_page');
          }
          );

          Post as a guest




















































































          Popular posts from this blog

          List item for chat from Array inside array React Native

          Thiostrepton

          Caerphilly