0

one small issue i have, how to make this code to work:

import { Component, OnInit } from '@angular/core';
import { FormGroup, FormControl,FormBuilder, Validators } from '@angular/forms';
import { Http, Response, Headers } from '@angular/http';
import { Router, ActivatedRoute, Params } from '@angular/router';
import { map,share } from 'rxjs/operators';
import {DataService} from '../data.service';

@Component({
  selector: 'app-change-room',
  templateUrl: './change-room.component.html',
  styleUrls: ['./change-room.component.css'],

})
export class ChangeRoomComponent implements OnInit {
    data: Array[Object];//error
    registerForm: FormGroup;
    http: Http;
    router: Router;
  postResponse: String;

  constructor(builder: FormBuilder, http: Http, router: Router, private dataService: DataService,route: ActivatedRoute) {

    this.data = this.dataService.getData();        
        console.log(this.data[0].roomname, this.data.tv);
        this.http = http;
        this.router = router;
        this.registerForm = builder.group({
         roomName: [""+this.data[0].roomname],
         hasTV: [""+this.data[0].tv],
         beds: [""+this.data[0].beds]


    });
}
ngOnInit() {

}
onModifyRoom(): void {

    var data1 = "roomName="+this.registerForm.value.roomName+"&hasTV="+this.registerForm.value.hasTV+"&beds="+this.registerForm.value.beds+"&brojkvadrata="+this.registerForm.value.brojkvadrata;
    var headers = new Headers();
    headers.append('Content-Type', 'application/x-www-form-urlencoded');
  this.http.post('http://localhost/it255/updateroom.php', data1, {headers: headers}).subscribe((result) => {
    this.router.navigateByUrl('rooms');
    alert("Succesfully changed room")
  }, (error) => {
    this.router.navigateByUrl('aboutus');
  });

}

}

i get errors like this : Generic type 'Array' requires 1 type argument(s). Generic type 'Array' requires 1 type argument(s).

What should i do to make this to work in angular 6, this worked when i triy in angular 2.

1 Answer 1

3

data: Array[Object] is not valid TS syntax.

If you want to define the variable data as an array of Objects, you can do

data: Object[];

or

data: Array<Object>;
Sign up to request clarification or add additional context in comments.

1 Comment

Thank you, i will see how to implement this :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.