Sunday, May 12, 2024
 Popular · Latest · Hot · Upcoming
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

 Answers
303

You need to add the specific type.



If it contains no data and is being used purely for the resolve/reject functionality, use:



Promise<void>


Ultimately this is a type signature like any other, so you can use:



Promise<any> 


https://basarat.gitbooks.io/typescript/content/docs/promise.html


[#60548] Wednesday, September 28, 2016, 8 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
arron

Total Points: 663
Total Questions: 119
Total Answers: 112

Location: Belize
Member since Mon, Jun 20, 2022
2 Years ago
;