angularjs - Cannot find name 'headers'. in angular 2 -
enter image description here working on angular 2.this ts file called getrandomquote() method in constructor. when run project below error:-
cannot find name 'headers'. did mean instance member 'this.headers'?
import {component, viewencapsulation, injectable} '@angular/core'; import {paginatepipe, paginationcontrolscmp, paginationservice} 'ng2-pagination'; import { http, response, headers,requestoptions } 'angular2/http'; import {basictablesservice} './basictables.service'; import {bacard} '../../../../theme/components'; import {hovertable} './components/hovertable'; import {borderedtable} './components/borderedtable'; import {condensedtable} './components/condensedtable'; import {stripedtable} './components/stripedtable'; import {contextualtable} './components/contextualtable'; import {responsivetable} './components/responsivetable'; import {authhttp, authconfig, auth_providers } 'angular2-jwt'; import {http_bindings} 'angular2/http'; @component({ selector: 'basic-tables', viewproviders: [paginationservice], pipes: [paginatepipe, responsivetable, contextualtable], encapsulation: viewencapsulation.none, directives: [bacard, hovertable, borderedtable, condensedtable, stripedtable, contextualtable, responsivetable, paginationcontrolscmp,http_bindings], styles: [require('./basictables.scss')], template: ` <todo-search></todo-search> <table class="table table-hover"> <div >enter id: <input type="text" #listfilter (keyup)="0" style="color:black" /></div> <div>alert on click<button (click)="clicked()" style="color:black">click</button></div> <span>{{ test }}</span> <tr class="black-muted-bg"> <th class="align-left">id</th> <th class="align-left">name</th> <th class="align-left">protocol</th> <th class="align-left">inbound business process</th> <th class="align-left">outbound business process</th> </tr> <tbody> <tr *ngfor="let item of randomquote | paginate: { itemsperpage: 20, currentpage: p } | responsivetable:listfilter.value "> <td>{{item.connectionid}}</td> <td>{{item.name}}</td> <td>{{item.protocol}}</td> <td>{{item.inboundbpname}}</td> <td>{{item.outboundbpname}}</td> </tr> </tbody> <pagination-controls (pagechange)="p = $event" #api></pagination-controls> </table> `, providers: [basictablesservice] }) export class basictables { public body = json.stringify( { "startindex": 0, "numofids": 15, "programid": null, "emailid":"admin@justransform.com", "searchstr":"", "transactionid":"", "status":"", "srcconnectionname":"", "destconnectionname":"", "inboundbpname":"", "outboundbpname":"", "filecontent":"" } ); public headers = new headers({ 'content-type': 'application/json' }); public options = new requestoptions({ headers: headers }); private url = 'http://uat.justransform.com:8080/justransform/transaction/find?sortbycolumn=transactionid&sortbyorder=desc'; randomquote:array<any> = []; getrandomquote() { this.http.post(this.url, this.body, this.options) .map((res:response) => res.json()) .subscribe( data => {this.randomquote = data}, err => this.logerror(err), () => console.log('random quote complete') ); } logerror(err) { console.error('there error: ' + err); } clicked(event) { alert("alert"); } constructor(public http: http) { this.getrandomquote(); } }
your code defines headers
attribute in class context , tries access directly after using headers
.
public headers = new headers({ 'content-type': 'application/json' }); public options = new requestoptions({ headers: headers });
the error message tells try:
cannot find name 'headers'. did mean instance member 'this.headers'?
this because defined headers
in class context. access it, have use this.headers
:
public options = new requestoptions({ headers: this.headers }); // ^ here
see typescript classes more information.
Comments
Post a Comment