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,
angularjs codeigniter-3
add a comment |
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,
angularjs codeigniter-3
add a comment |
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,
angularjs codeigniter-3
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
angularjs codeigniter-3
asked 2 days ago
danko12
497
497
add a comment |
add a comment |
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
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
add a comment |
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
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
add a comment |
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
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
add a comment |
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
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
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.
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
add a comment |
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
add a comment |
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password