Skip to content

Instantly share code, notes, and snippets.

@marianoqueirel
Last active October 13, 2016 14:30
Show Gist options
  • Save marianoqueirel/8242dbf4145a8310bf822c94cc3291dd to your computer and use it in GitHub Desktop.
Save marianoqueirel/8242dbf4145a8310bf822c94cc3291dd to your computer and use it in GitHub Desktop.
Help / Promises
'use strict';
import angular from 'angular';
import uiRouter from 'angular-ui-router';
import routes from './login.routes';
export class LoginComponent {
/*@ngInject*/
constructor(Auth, $state) {
this.Auth = Auth;
this.$state = $state;
this.errors = {login: ''};
}
login(form) {
this.submitted = true;
const user = {
email: this.user.email,
password: this.user.password
};
if (form.$valid) {
this.Auth.login(user)
.then(
(data) => {
this.errors.login = data;
// Logged in, redirect to home
//this.$state.go('main');
},
(err) => {
this.errors.login = err;
}
);
}
}
close() {
this.submitted = false;
this.errors = {};
}
}
export default angular.module('sisaApp.login', [uiRouter])
.config(routes)
.component('login', {
template: require('./login.html'),
controller: LoginComponent
})
.name;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment