Advertisement
Guest User

Untitled

a guest
Feb 22nd, 2019
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.13 KB | None | 0 0
  1. import { Component, OnInit } from '@angular/core';
  2. import { IPost, IUser} from '../shared/interfaces';
  3.  
  4. @Component({
  5. selector: 'app-main',
  6. templateUrl: './main.component.html',
  7. styleUrls: ['./main.component.css']
  8. })
  9. export class MainComponent implements OnInit {
  10. userList: Array<IUser>;
  11. loginField: string;
  12. passField: string;
  13. currentUser: object;
  14.  
  15. constructor() {
  16. }
  17.  
  18. ngOnInit() {
  19. }
  20.  
  21. public addUser() {
  22. userList.push(new NewUser(this.loginField, this.passField));
  23. this.loginField = '';
  24. this.passField = '';
  25. console.log(userList);
  26. }
  27.  
  28. public LogIn(): void {
  29. for (const i in userList) {
  30. if (userList[i].userName === this.loginField && userList[i].userPass === this.passField) {
  31. this.currentUser = userList[i];
  32. this.loginField = this.passField = '';
  33. console.log(this.currentUser);
  34. } else if (userList[i].userName !== this.loginField && userList[i].userPass !== this.passField) {
  35. this.currentUser = userList[1];
  36. this.loginField = this.passField = '';
  37. console.log(this.currentUser);
  38. }
  39. }
  40. }
  41.  
  42. }
  43.  
  44. class NewPost implements IPost {
  45. theme: string;
  46. content: string;
  47. constructor( theme: string, content: string) {
  48. this.theme = theme;
  49. this.content = content;
  50. }
  51. }
  52.  
  53. class NewUser implements IUser {
  54. userName: string;
  55. userPass: string;
  56. userRoot: boolean;
  57. userPost: Array<IPost>;
  58. themeField: string;
  59. contentField: string;
  60. addPost(): void {
  61. this.userPost.push(new NewPost(this.themeField, this.contentField));
  62. console.log(this.userPost);
  63. }
  64. constructor(userName: string, userPass: string) {
  65. this.userName = userName;
  66. this.userPass = userPass;
  67. this.userRoot = false;
  68. this.userPost = [];
  69. }
  70. }
  71.  
  72. const userList: Array<IUser> = [
  73. {
  74. userName: 'admin',
  75. userPass: 'admin',
  76. userRoot: true,
  77. userPost: [
  78. {
  79. theme: 'Create a Blog',
  80. content: 'I just created this blog'
  81. }
  82. ]
  83. } as IUser,
  84. {
  85. userName: 'Guest',
  86. userPass: '',
  87. userRoot: false,
  88. userPost: [
  89. {
  90. theme: 'First time here',
  91. content: 'I like this blog'
  92. }
  93. ]
  94. } as IUser
  95. ];
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement