Advertisement
randomCodes

ng4 - task 01

Aug 16th, 2017
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //In my code i don't implement item 6, instead i use a ternary function to change the loadState value.
  2.  
  3. //dashboard.component.ts
  4. import { Component } from '@angular/core';
  5. @Component({
  6.  selector: 'app-dashboard',
  7.  template: `
  8.  <button (click)="onChangeState()">Change Load State</button>
  9.  <p>Current state: {{ loadState }}</p>
  10.  `
  11. })
  12. export class DashboardComponent {
  13.  loadState = 'loading';
  14.  onChangeState() {
  15.  this.loadState === 'loading' ? this.loadState = 'finished' : this.loadState = 'loading';
  16.  }
  17. }
  18. //app.module.ts
  19. import { FormsModule } from '@angular/forms';
  20. ...
  21. import { DashboardComponent } from './dashboard.component';
  22. @NgModule({
  23.  declarations: [
  24. ...
  25.  DashboardComponent
  26.  ],
  27.  imports: [
  28.  ...
  29.  FormsModule
  30.  ],
  31.  providers: [],
  32.  bootstrap: [AppComponent]
  33. })
  34. export class AppModule { }
  35. //app.component.ts
  36. ...
  37. <app-dashboard></app-dashboard>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement