176
rated 0 times
[
179]
[
3]
/ answers: 1 / hits: 26004
/ 8 Years ago, thu, september 29, 2016, 12:00:00
I have used Promise and observables logic to fetch data from server using get.
It was working till yesterday. SUddenly it starts throwing the above error.
Please help me finding the error.
I am getting Generic type 'Promise' requires 1 type argument(s) error.
@Injectable()
export class myBlogService{
// Property to hold root server URL i.e host
private serverUrl:string = app/data.json
constructor(private http:Http) {}
// check function in service to check control is coming to service
check(){
alert(getting clicked from service);
}
// get function to get data from server
// basically blog datas
get(): Promise {
return this.http.get(this.serverUrl)
.map(response => response.json())
}
}
/**
*
* My Components
*
*/
@Component({
selector: 'my-app',
providers: [myBlogService],
styleUrls: ['app/css/app.css'],
template: `
<h1 (click)= check()>My First Angular 2 App</h1>
<button (click)=get()>Get My Name</button>
<h1>{{getResponse.name}}</h1>
`
})
export class myBlogApp {
// Property to hold blog data
public getResponse = {name: , age: };
constructor(protected myblogservice:myBlogService){}
// check function to check control is going to service
check() {
this.myblogservice.check();
}
// get function calls service get function which return data from server
get(){
this.myblogservice.get().subscribe(data => {
this.getResponse = data;
});
}
}
/**
*
* NgModule Declaration
*
*/
@NgModule({
imports: [ BrowserModule, HttpModule ],
declarations: [ myBlogApp ],
providers: [ ],
bootstrap: [ myBlogApp ]
})
export class app{}
/**
*
* App engine entry point
*
*/
const platform = platformBrowserDynamic();
platform.bootstrapModule(app);
When promise: is given, still it gives issue like
error TS2339: Property 'subscribe' does not exist on type 'Promise'.
I tried different solution but no luck yet.
More From » angular