输入'标题'没有与类型' RequestOptionsArgs'

时间:2017-10-08 15:07:31

标签: angular

我已经导入了标题,我已经包含了对象,网址和标题。但它显示错误

  

键入'标题'没有与' RequestOptionsArgs'

类型相同的属性

我的代码:

class myClass
{
    public $inputNumber = 27;
    public $inputArray = array(1, 2, 4);
    public $outputArray = array($inputArray[0]*$inputNumber, $inputArray[1]*$inputNumber, $inputArray[2]*$inputNumber);

    public function printOutput()
    {
        return "1st value is " . $this->outputArray[0] . "<br>";
        return "2nd value is " . $this->outputArray[1] . "<br>";
        return "3rd value is " . $this->outputArray[2] . "<br>";
    }
}

$obj = new myClass;

echo $obj->printOutput();

2 个答案:

答案 0 :(得分:1)

您需要在Headers中传递RequestOptions,然后再将其传递给post(...)

return this.http.post('http://ip/ex/api/api/JsonServices.php',JSON.stringify(obj),
    new RequestOptions(headers: headers))

另见

答案 1 :(得分:0)

标头只是http请求的其中一个选项。尝试使用RequestOptions

import { RequestOptions } from '@angular/router';

getContactData(aplhaNumericId:any){
    let obj = {aplhaNumericId:aplhaNumericId};
    let headers=new Headers();
    headers.append('Content-Type','application/json; charset=utf=8');
    // add this 
    let options = new RequestOptions({headers: headers});
enter code here
    return this.http.post('http://ip/ex/api/api/JsonServices.php', JSON.stringify(obj), options))
        .map((res:Response) => res.json());
}

请注意,这是针对旧的HttpModule