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 Nov 10 at 12:52









      danko12

      547




      547
























          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





















          • The addition of ng-click has helped.
            – danko12
            Nov 10 at 15:34











          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',
          autoActivateHeartbeat: false,
          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















          Required, but never shown

























          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





















          • The addition of ng-click has helped.
            – danko12
            Nov 10 at 15:34















          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





















          • The addition of ng-click has helped.
            – danko12
            Nov 10 at 15:34













          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












          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












          share|improve this answer



          share|improve this answer










          answered Nov 10 at 13:12









          BartoszTermena

          581129




          581129












          • The addition of ng-click has helped.
            – danko12
            Nov 10 at 15:34


















          • The addition of ng-click has helped.
            – danko12
            Nov 10 at 15:34
















          The addition of ng-click has helped.
          – danko12
          Nov 10 at 15:34




          The addition of ng-click has helped.
          – danko12
          Nov 10 at 15:34


















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.





          Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


          Please pay close attention to the following guidance:


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          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















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          這個網誌中的熱門文章

          Tangent Lines Diagram Along Smooth Curve

          Yusuf al-Mu'taman ibn Hud

          Zucchini