Advertisement
majczel23000

[ANGULAR] TODOLista

Jul 3rd, 2018
134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.68 KB | None | 0 0
  1. app.module.ts:
  2.  
  3. import { BrowserModule } from '@angular/platform-browser';
  4. import { NgModule } from '@angular/core';
  5. import { FormsModule } from '@angular/forms';
  6.  
  7. import { AppComponent } from './app.component';
  8. import { HeaderComponent } from './components/header/header.component';
  9. import { TodoInputComponent } from './components/todo-input/todo-input.component';
  10.  
  11. import { TodoService } from './services/todo.service';
  12. import { TodoItemComponent } from './components/todo-item/todo-item.component';
  13.  
  14. @NgModule({
  15. declarations: [
  16. AppComponent,
  17. HeaderComponent,
  18. TodoInputComponent,
  19. TodoItemComponent
  20. ],
  21. imports: [
  22. BrowserModule,
  23. FormsModule
  24. ],
  25. providers: [
  26. TodoService
  27. ],
  28. bootstrap: [AppComponent]
  29. })
  30. export class AppModule { }
  31.  
  32.  
  33. ===================================================================================
  34. ===================================================================================
  35.  
  36. app.component.ts:
  37.  
  38. import { Component } from '@angular/core';
  39. import { TodoService } from './services/todo.service';
  40. import { Todo } from './classes/todo';
  41.  
  42. @Component({
  43. selector: 'app-root',
  44. templateUrl: './app.component.html',
  45. styleUrls: ['./app.component.css']
  46. })
  47. export class AppComponent {
  48.  
  49. constructor(private todoService: TodoService) {
  50. }
  51. }
  52.  
  53. ===================================================================================
  54. ===================================================================================
  55.  
  56. app.component.html:
  57.  
  58. <div class="App">
  59. <div class="todo-wrapper">
  60. <app-header></app-header>
  61. <app-todo-input></app-todo-input>
  62. <div *ngFor="let todo of todoService.getTodos()">
  63. <app-todo-item [todo]="todo"></app-todo-item>
  64. </div>
  65. </div>
  66. </div>
  67.  
  68.  
  69. ===================================================================================
  70. ===================================================================================
  71.  
  72. app.component.css:
  73.  
  74. .App {
  75. text-align: center;
  76. }
  77.  
  78. .todo-wrapper {
  79. margin: 20px auto 20px auto;
  80. width: 500px;
  81. min-height: 600px;
  82. border: 5px solid rgba(73, 204, 249, 1.0);
  83. padding: 20px;
  84. }
  85.  
  86. ===================================================================================
  87. ===================================================================================
  88.  
  89.  
  90. classes/todo.ts:
  91.  
  92. export class Todo {
  93. id: number;
  94. text: string;
  95.  
  96. constructor(id: number, text: string) {
  97. this.id = id;
  98. this.text = text;
  99. }
  100. }
  101.  
  102. ===================================================================================
  103. ===================================================================================
  104.  
  105. components/header/header.component.html:
  106.  
  107. <h1>Lista TODO</h1>
  108.  
  109. ===================================================================================
  110. ===================================================================================
  111.  
  112. components/header/header.component.ts:
  113.  
  114. import { Component, OnInit } from '@angular/core';
  115.  
  116. @Component({
  117. selector: 'app-header',
  118. templateUrl: './header.component.html',
  119. styleUrls: ['./header.component.css']
  120. })
  121. export class HeaderComponent implements OnInit {
  122.  
  123. constructor() { }
  124.  
  125. ngOnInit() {
  126. }
  127.  
  128. }
  129.  
  130. ===================================================================================
  131. ===================================================================================
  132.  
  133. components/todo-input/todo-input.component.css:
  134.  
  135. .todo-input-wrapper {
  136. margin-bottom: 20px;
  137. }
  138. .btn {
  139. outline: none;
  140. box-shadow: none;
  141. padding: 7px;
  142. }
  143.  
  144. .btn-primary {
  145. color: black;
  146. border-color: black;
  147. background-color: transparent;
  148. }
  149.  
  150. input {
  151. width: 80%;
  152. border: 2px solid black;
  153. margin-right: 10px;
  154. padding: 5px;
  155. line-height: 17px;
  156. }
  157.  
  158. input:focus {
  159. border: 2px solid grey;
  160. }
  161.  
  162.  
  163. ===================================================================================
  164. ===================================================================================
  165.  
  166. components/todo-input/todo-input.component.html:
  167.  
  168. <div class="todo-input-wrapper">
  169. <input type="text" [(ngModel)]="todoText" value={{todoText}}/>
  170. <button class="btn btn-primary" (click)="addTodo()">Submit</button>
  171. </div>
  172.  
  173. ===================================================================================
  174. ===================================================================================
  175.  
  176. components/todo-input/todo-input.component.ts:
  177.  
  178. import { Component, OnInit } from '@angular/core';
  179. import { TodoService } from '../../services/todo.service';
  180.  
  181. @Component({
  182. selector: 'app-todo-input',
  183. templateUrl: './todo-input.component.html',
  184. styleUrls: ['./todo-input.component.css']
  185. })
  186. export class TodoInputComponent implements OnInit {
  187.  
  188. public todoText: string;
  189.  
  190. constructor(private todoService: TodoService) {
  191. this.todoText = '';
  192. }
  193.  
  194. ngOnInit() {
  195. }
  196.  
  197. //dodanie zadania Todo
  198. private addTodo(): void {
  199. this.todoService.addTodo(this.todoText);
  200. this.todoText = '';
  201. }
  202. }
  203.  
  204.  
  205. ===================================================================================
  206. ===================================================================================
  207.  
  208. components/todo-item/todo-item.component.css:
  209.  
  210. .todoWrapper {
  211. border-bottom: 1px solid #efefef;
  212. text-align: left;
  213. margin-bottom: 10px;
  214. }
  215. .removeTodo {
  216. margin-right: 20px;
  217. margin-bottom: 10px;
  218. outline: none;
  219. box-shadow: none;
  220. border-width: 2px;
  221. border-radius: 3px;
  222. border-style: solid;
  223. padding: 8px;
  224. color: rgba(203, 20, 32, 0.4);
  225. border-color: rgba(203, 20, 32, 0.4);
  226. background-color: transparent;
  227. }
  228.  
  229. ===================================================================================
  230. ===================================================================================
  231.  
  232. components/todo-item/todo-item.component.html:
  233.  
  234. <div class="todoWrapper">
  235. <button class="removeTodo" (click)="removeTodo()">remove</button>{{todo.text}}
  236. </div>
  237.  
  238. ===================================================================================
  239. ===================================================================================
  240.  
  241. components/todo-item/todo-item.component.ts:
  242.  
  243. import { Component, OnInit, Input } from '@angular/core';
  244. import { Todo } from '../../classes/todo';
  245. import { TodoService } from '../../services/todo.service';
  246.  
  247. @Component({
  248. selector: 'app-todo-item',
  249. templateUrl: './todo-item.component.html',
  250. styleUrls: ['./todo-item.component.css']
  251. })
  252. export class TodoItemComponent implements OnInit {
  253.  
  254. @Input()
  255. private todo: Todo;
  256.  
  257. constructor(private todoService: TodoService) { }
  258.  
  259. ngOnInit() {
  260. }
  261.  
  262. private removeTodo(): void {
  263. this.todoService.removeTodo(this.todo.id);
  264. }
  265.  
  266. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement