SHARE
TWEET

Untitled

a guest Oct 22nd, 2016 66 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // command.ts
  2.  
  3. import {ActionBase} from "./action";
  4. import {Component} from "@angular/core";
  5. import {SpecZero, SpecText, ISpec} from "./spec"
  6.  
  7. @Component({
  8.   selector: "df-command",
  9.   templateUrl: "command.html"
  10. })
  11. export class Command {
  12.   test: string;
  13.   spec_parts: ISpec[] = [];
  14.   action: ActionBase[] = [];
  15.  
  16.   constructor() {
  17.     this.test = "" + Math.random();
  18.     /*
  19.     I think
  20.      <df-spec *ngFor="let spec_part of spec_parts">
  21.      is not actually accessing this list, but just making a new <df-spec>
  22.      for each item in the list...
  23.      */
  24.  
  25.     let s = new SpecZero();
  26.     s.type = 0;
  27.     s.value = "MY_TEST_0";
  28.     this.spec_parts.push(s);
  29.  
  30.     let a = new SpecText();
  31.     a.value = "MY_TEST_1";
  32.     a.type = 1;
  33.     this.spec_parts.push(a);
  34.  
  35.     let x = new ActionBase();
  36.     this.action.push(x);
  37.   }
  38.  
  39. }
  40. //   spec.ts      ----------------------------------------
  41. import {Component, Injectable} from "@angular/core";
  42.  
  43. export interface ISpec {
  44.   type: number;
  45.   value: string;
  46. }
  47.  
  48. @Component({
  49.   selector: 'df-spec',
  50.   templateUrl: "spec.html"
  51. })
  52. export class SpecWrapper {
  53.   @Injectable()
  54.   public spec: ISpec;
  55. }
  56.  
  57.  
  58. export class SpecZero implements ISpec {
  59.   public type: number = 0;
  60.   public value: string = "SB";
  61. }
  62.  
  63. export class SpecText implements ISpec {
  64.   public type: number = 1;
  65.   public value: string = "ST";
  66. }
  67. // command.html -----------------------------------------
  68. <span>COMMAND:</span>
  69. <ul>
  70.   <div *ngFor="let spec_part of spec_parts">
  71.     {{spec_part}}
  72.   </div>
  73.   <df-action *ngFor="let action_part of action"></df-action>
  74. </ul>
  75. //  spec.html            ------------------
  76. <span>value: {{value}}| </span>
  77. <span>type: {{type}}| </span>
  78. <span *ngIf="type===1">is one</span>
  79. <span *ngIf="type!==1">not one</span>
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top