title: Angular 5 service variable value updating
body: <p>I can not update my angular service variable value. </p>
  
  <p>I have two non-related components, and i want to send updated object from one to other one , using service . But I can't update object in service. </p>
  
  <hr>
  
  <p>First component :</p>
  
  <pre><code>import { SoruService } from '../soru.service';
  import { SoruModel, SecenekModel } from '../soruModel';
  
  @Component({
      selector: 'app-first',
      templateUrl: './first.component.html',
      styleUrls: ['./first.component.scss'],
      providers: [SoruService]
  })
  export class FirstComponent implements OnInit {
      public soruLst : [SoruModel];
  
      constructor( private soruServis : SoruService ) { }
  
      ngOnInit(){
          this.soruServis.getirSoruLst().subscribe( veri =&gt; {
              this.soruLst = veri as [SoruModel];
          })
      }
  
      //// MAKE SOME CHANGES ON "soruLst" locally 
  
      // Send updated 'soruLst' to service 
      updateSoruLst(){
          this.soruServis.updateSoruLst(this.soruLst);
      }
  
  }
  </code></pre>
  
  <hr>
  
  <p>My Service :</p>
  
  <pre><code>import { Injectable } from '@angular/core';
  import { SoruModel, SecenekModel } from './soruModel';
  import { Http } from '@angular/http';
  
  const metaJson = 'assets/data/Meta.json';
  
  @Injectable()
  export class SoruService {
  
      public sorular = [] as [SoruModel];
  
      constructor( private http:Http ) {
          this.sorular = [] as [SoruModel];
      }
  
      getirSoruLst() {
          return this.http.get(metaJson)
          .map(yanit =&gt; yanit.json())
      }
  
      updateSoruLst( soruLst : [SoruModel] ) {
               this.sorular = soruLst;
       }
  
      getSorular() : [SoruModel] {
          return this.sorular;
      }
  
  }
  </code></pre>
  
  <hr>
  
  <p>Second Component :</p>
  
  <pre><code>mport { SoruService } from '../soru.service';
  import { SoruModel, SecenekModel } from '../soruModel';
  
  @Component({
      selector: 'app-second',
      templateUrl: './second.component.html',
      styleUrls: ['./second.component.scss'],
      providers: [SoruService]
  })
  export class SecondComponent implements OnInit {
      public soruLst : [SoruModel];
  
      constructor( private soruServis : SoruService ) { }
  
      ngOnInit(){
          this.soruLst = this.soruServis.getSorular();
          console.log(this.soruLst);
      }
  }
  </code></pre>
  
  <hr>
  
  <p>This is what i want to do :</p>
  
  <ol>
  <li><p>in FirstComponent, get 'soruLst' from service and change it locally (Success)</p></li>
  <li><p>in FirstComponent, send changed 'soruLst' to service (Success - updateSoruLst )</p></li>
  <li><p>in Service, update 'sorular', in 'updateSoruLst' (Fail - it's not changing, only changing in function scope but i still can't read updated value) . I have problem with that :</p>
  
  <blockquote>
    <p>updateSoruLst( soruLst : [SoruModel] ) {
        this.sorular = soruLst; }</p>
  </blockquote></li>
  </ol>
  
  <p>"this.sorular" value doesn't change globally. </p>
  
  <ol start="4">
  <li>in SecondComponent, read updated 'sorular' from service ( Fail, still can't read updated value)</li>
  </ol>
  
  <hr>
  
  <p>I think i must change my service , but could't find where must i change..</p>
  
  <p>How can i update my object in service ?</p>