के लिए काम नहीं कर रहा है मैं एचटीपी सेवा के साथ एक अजाक्स कॉल करने की कोशिश कर रहा हूं, जो ठीक काम कर रहा है।पकड़ http.get Angular2
अब मैं विफलता के मामलों को संभालना चाहता हूं। उदाहरण अगर हमें 404 या कोई अन्य त्रुटियां मिलती हैं।
मैं निम्नलिखित कोड का उपयोग कर रहा हूं।
import {Component,Inject} from '@angular/core';
import {Http, Response,HTTP_PROVIDERS} from '@angular/http';
import {DoService} from './service';
import 'rxjs/Rx';
import 'rxjs/add/operator/catch';
@Component({
selector: 'comp-one',
template: `<h2>My First Angular 2 App</h2>{{data}}
<input type="button" (click)="doSomething()" value="Do Http"/>`
})
export class ComponentOne {
constructor(public _http:Http){
console.log("It is from ComponentOne constructor..");
this._http = _http;
}
data:Object;
doSomething(){
console.log("It is from doSomething ComponentOne");
let temp:any = this._http.get('people.json')//people.json is not exist, intendedly maing any error
.map(res => res.json())
.catch((err:any)=>{ console.log("Something is wrong..")});// If i keep this line i am getting errors like "Argument of type '(err:any) => void' is not assignable to parameter of type '(err: any, caught: Observable<any>) => Observable<{}>"
temp.subscribe(
(res:any)=> {this.data = res._body; console.log(res)},
(error:any)=>{ console.log("It isf from error..")},//It is not even getting called this block
() => console.log('thire,,,ddjfladjfljasdlfj'));//In one of the forum they suggested to use this 3rd perameter, this is also not working for me.
}
}
क्या हुआ अगर मैं एक नमूदार वापस जाने के लिए चाहते है? मैं अपने स्वयं के फ़ंक्शन में त्रुटि को संभालना चाहता हूं, एंजुलर को – Blauhirn
शून्य स्पष्टीकरण देने दें – Flame