Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import { Component, OnInit } from '@angular/core';
- import { IPost, IUser} from '../shared/interfaces';
- @Component({
- selector: 'app-main',
- templateUrl: './main.component.html',
- styleUrls: ['./main.component.css']
- })
- export class MainComponent implements OnInit {
- userList: Array<IUser>;
- loginField: string;
- passField: string;
- currentUser: object;
- constructor() {
- }
- ngOnInit() {
- }
- public addUser() {
- userList.push(new NewUser(this.loginField, this.passField));
- this.loginField = '';
- this.passField = '';
- console.log(userList);
- }
- public LogIn(): void {
- for (const i in userList) {
- if (userList[i].userName === this.loginField && userList[i].userPass === this.passField) {
- this.currentUser = userList[i];
- this.loginField = this.passField = '';
- console.log(this.currentUser);
- } else if (userList[i].userName !== this.loginField && userList[i].userPass !== this.passField) {
- this.currentUser = userList[1];
- this.loginField = this.passField = '';
- console.log(this.currentUser);
- }
- }
- }
- }
- class NewPost implements IPost {
- theme: string;
- content: string;
- constructor( theme: string, content: string) {
- this.theme = theme;
- this.content = content;
- }
- }
- class NewUser implements IUser {
- userName: string;
- userPass: string;
- userRoot: boolean;
- userPost: Array<IPost>;
- themeField: string;
- contentField: string;
- addPost(): void {
- this.userPost.push(new NewPost(this.themeField, this.contentField));
- console.log(this.userPost);
- }
- constructor(userName: string, userPass: string) {
- this.userName = userName;
- this.userPass = userPass;
- this.userRoot = false;
- this.userPost = [];
- }
- }
- const userList: Array<IUser> = [
- {
- userName: 'admin',
- userPass: 'admin',
- userRoot: true,
- userPost: [
- {
- theme: 'Create a Blog',
- content: 'I just created this blog'
- }
- ]
- } as IUser,
- {
- userName: 'Guest',
- userPass: '',
- userRoot: false,
- userPost: [
- {
- theme: 'First time here',
- content: 'I like this blog'
- }
- ]
- } as IUser
- ];
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement