javascript - angular 2 two way data binding or what? -


hi guys need bit of start :)

well i'm trying load bunch of light-bulb status action button them fired-up/down on angular 2 app. code below working on 1 webpage on computer a. if load page @ same time on computer b every change on doesn't appear on b. tryed put on 2 data binding gives me same result don't know if it's real problem or maybe server not updating other client ? think ?

import {component, inject} "angular2/core"; import {http_providers, http, headers} "angular2/http"; import {ledservice} "./to-service"; import {ledmodel} "./to-model"; import {ledstatus} "./to-status"; // import {ledbutton} "./to-button";  @component({   selector:'led-list',   providers: [http_providers],   directives:[ledstatus],   template:`   <table>     <thead>       <th>component</th>       <th>status</th>       <th>action</th>     </thead>     <tbody *ngfor="#led of ledservice.leds">     <tr>     <td>{{led.name}}</td>     <td><led-status [led]="led"></led-status></td>     <td><button (click)="onclick(led)" >on</button>     <button (click)="offclick(led)">off</button></td>     </tr>     </tbody>   </table>`,   styles:[`     h1 {       color: #f39c12     }     div {       padding: 10px;       color: #bdc3c7;     }     table, th, td {       border-bottom : 2px solid grey;       border-collapse: collapse;       padding: 10px;       text-align: center;       color: #bdc3c7;     }     tr:hover {       background-color: #7f8c8d;     }   `] }) export class ledlist{   // public ledarray:ledmodel[]=[];    constructor(     public ledservice:ledservice,     public http:http   ){     this.http.get('/api/bears').subscribe(res => {       this.ledservice.leds = res.json();       // this.ledarray = res.json();       console.log(this.ledservice.leds);     });     // console.log(this.data);   }   active:boolean = false;   toggleactivestate() {     this.active = !this.active;   }    onclick(value){     value.status = "on";     value.color = "green";     console.log(value.name,value.status);     var modchange = "name="+ value.name + "&pin=" + value.pin + "&status=" + value.status +"&color=" + value.color;     var header = new headers();     header.append('content-type', 'application/x-www-form-urlencoded');     this.http.put('http://localhost:8080/api/bears/' + value._id,modchange,{       headers: header     })     .subscribe(       res => console.log(res.json())     )   }   offclick(value){     value.status = "off";     value.color = "red";     var modchange = "name="+ value.name + "&pin=" + value.pin + "&status=" + value.status +"&color=" + value.color;     var header = new headers();     header.append('content-type', 'application/x-www-form-urlencoded');     this.http.put('http://localhost:8080/api/bears/' + value._id,modchange,{       headers: header     })     .subscribe(       res => console.log(res.json())     )     //console.log(this.buttonoffmodel);   } } 


Comments

Popular posts from this blog

sublimetext3 - what keyboard shortcut is to comment/uncomment for this script tag in sublime -

java - No use of nillable="0" in SOAP Webservice -

ubuntu - Laravel 5.2 quickstart guide gives Not Found Error -