title: Assign values from http get response to variables in angular
body: <p>I am creating a settings application that has slide toggles.Currently I am using local storage to save the toggle state.However I want to change the toggle stage based on the server response.I want to toggle buttons based on the values set in a database.But I'm unbael to fetch the values.I am able to log the whole response but I don't know how to fetch values from that http response.Please help.Thanks in advance></p>
  
  <p>Here is my code:</p>
  
  <p>Component</p>
  
  <pre><code>export class PolicyComponent implements OnInit {
  
        @Output() change: EventEmitter&lt;MatSlideToggleChange&gt;;
        @Input() checked: boolean;
  
        isChecked = true;
        formGroup: FormGroup;
        filteringSchedule: boolean;
        toggle: boolean;
  
        policy:Policy[];
        constructor(
          private formBuilder: FormBuilder,private policyService:PolicyService
        ) { }
  
        ngOnInit() {
          this.filteringSchedule = JSON.parse(sessionStorage.getItem('toggleButtonState'));
          this.formGroup = this.formBuilder.group({
            enableWifi: this.filteringSchedule,
            acceptTerms: [false, Validators.requiredTrue]
          });
  
          this.policyService.getPolicy().subscribe(
          (response)=&gt;{
      console.log(response);    })
  
  
        }
  
    onFormSubmit(formValue: any) {
      alert(JSON.stringify(formValue, null, 2));
    }
  
    onChange(ob: MatSlideToggleChange) {
      this.filteringSchedule = !this.filteringSchedule;
      sessionStorage.setItem('toggleButtonState', JSON.stringify(this.filteringSchedule));
    }
  
  }
  </code></pre>
  
  <p>Model:</p>
  
  <pre><code>export class Policy
  {
      id:number;
      policy1:string;
      policy2:string;
  }
  </code></pre>
  
  <p>Service:</p>
  
  <pre><code>export class PolicyService {
  
    constructor(private http:HttpClient) { }
    baseUrl:string="/policy";
  
    getPolicy()
    {
      return this.http.get&lt;Policy[]&gt;(this.baseUrl);
  
    }
  }
  </code></pre>
  
  <p>Response is:</p>
  
  <pre><code>[
      {
          "id": 1,
          "policy1": "a",
          "policy2": "b"
      }
  ]
  </code></pre>