Advertisement
Guest User

Untitled

a guest
Jan 11th, 2016
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.94 KB | None | 0 0
  1. import {Component, View, Inject} from 'angular2/core';
  2. import {NgIf} from 'angular2/common';
  3. import {Router, RouteConfig, RouterLink, RouterOutlet, ROUTER_PROVIDERS} from 'angular2/router';
  4.  
  5.  
  6. import {HomeComponent} from '../home/home';
  7. import {LoginComponent} from '../login/login';
  8.  
  9. @Component({
  10. selector: 'app',
  11. })
  12. @View({
  13. templateUrl: '/scripts/src/components/app/app.html',
  14. directives: [RouterLink, RouterOutlet, NgIf]
  15. })
  16. export class App {
  17. constructor(
  18. @Inject(Router) router: Router
  19. ) {
  20. this.devIsLogin=false;
  21. router.config([
  22. { path: '', component: HomeComponent, as: 'Home' },
  23. { path: '/login', component: LoginComponent, as: 'Login' }
  24. ]);
  25. }
  26. }
  27.  
  28. ///<reference path="../../../node_modules/angular2/typings/node/node.d.ts" />
  29.  
  30. import {Component, View, Inject} from 'angular2/core';
  31. import {FormBuilder, FORM_DIRECTIVES } from 'angular2/common';
  32. import {Http, HTTP_PROVIDERS} from 'angular2/http';
  33. import {LoginService} from '../../services/loginService';
  34. import {Router} from 'angular2/router';
  35.  
  36. @Component({
  37. selector: 'login',
  38. providers: [HTTP_PROVIDERS]
  39. })
  40. @View({
  41. templateUrl: '/scripts/src/components/login/login.html',
  42. directives: [FORM_DIRECTIVES]
  43. })
  44.  
  45. export class LoginComponent {
  46. userName: string;
  47. password: string;
  48. showError: boolean;
  49. constructor(
  50. @Inject(LoginService) private loginService: LoginService,
  51. @Inject(Router) private router: Router
  52. ) {
  53. this.userName = '';
  54. this.password = '';
  55. this.showError = false;
  56. }
  57. login() {
  58. var data = {
  59. userName: this.userName,
  60. password: this.password
  61. }
  62. this.loginService.login(data, (res) => {
  63. this.showError = false;
  64. // and then we redirect the user to the home
  65. this.router.parent.navigate(['/Home']);
  66. }, (err) => {
  67. this.showError = true;
  68. });
  69. }
  70. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement