Guest User

Untitled

a guest
Oct 23rd, 2017
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.77 KB | None | 0 0
  1. import { Component, Input, OnInit } from '@angular/core';
  2. import { Subscription } from 'rxjs/Subscription';
  3. import { DataService } from './data.service'
  4.  
  5. @Component({
  6. selector: 'tr[app-myComp]',
  7. template: `
  8. <td><button [disabled]="isDisabled">{{data.prop1}}</button></td>
  9. <td><button [disabled]="isDisabled">{{data.prop2}}</button></td>
  10. `
  11. })
  12.  
  13. export class MyComponent implements OnInit {
  14. subscription: Subscription;
  15.  
  16. @Input()
  17. isDisabled: boolean;
  18.  
  19. @Input()
  20. data: {prop1: number, prop2: number};
  21.  
  22. constructor(public service: DataService) {
  23. this.subscription = service.disabled$.subscribe(
  24. () => {
  25. this.isDisabled = true;
  26. }
  27. );
  28. }
  29.  
  30. ngOnInit() {}
  31.  
  32. ngOnDestroy(){
  33. this.subscription.unsubscribe();
  34. }
  35.  
  36. }
  37.  
  38. import { AfterViewInit, Component, QueryList, ViewChildren } from '@angular/core';
  39.  
  40. import { MyComponent } from './myComponent'
  41. import { DataService } from './data.service'
  42.  
  43. @Component({
  44. selector: 'app-body',
  45. template: `<table>
  46. <tr class="">
  47. <td>buttons</td>
  48. </tr>
  49. <tr app-myComp [isDisabled]="isDisabled" [data]="data" [isDisabled]="isDisabled" (dblclick)="makeDisabled()"></tr>
  50. </table>
  51.  
  52. <button (click)="getNewData()">Get</button>
  53. `,
  54. })
  55. export class AppComponent implements AfterViewInit {
  56.  
  57. constructor(
  58. public service: DataService
  59. ){}
  60.  
  61. isDisabled: boolean = false;
  62. data: {prop1: number, prop2: number} = {prop1: 13, prop2: 16};
  63.  
  64. makeDisabled(): void {
  65. this.service.makeDisabled()
  66. }
  67.  
  68. getNewData(): void {
  69. //service call
  70. this.data = {prop1: 45, prop2: 56};
  71. this.isDisabled = !this.isDisabled;
  72. this.isDisabled = false;
  73. }
  74. }
Add Comment
Please, Sign In to add comment