javascript - Angular 2 / Typescript - TypeError: ClassName is not a constructor -
i learning angular 2 , ran error while trying create service. tried searching solution, cannot see mistake.
error:
angular2-polyfills.js:1243 typeerror: tweet not constructor
code:
export class tweetservice{ gettweets(){ return tweets; } } let tweets = new tweet("url", "author 1", "handle 1", true, 50); class tweet { image: string; author: string; handle: string; status: "lorem ipsum dolor sit amet."; isliked: boolean; favorites: number; constructor(img, aut, hndl, ilkd, fav){ img = this.image; aut = this.author; hndl = this.handle; ilkd = this.isliked; fav = this.favorites; } }
your let statement floating outside class declarations. work (but in real app setting tweets based on http call or something):
import {injectable} '@angular/core'; @injectable() export class tweetservice{ gettweets(){ let tweets = new tweet("url", "author 1", "handle 1", true, 50); return tweets; } } class tweet { image: string; author: string; handle: string; status: "lorem ipsum dolor sit amet."; isliked: boolean; favorites: number; constructor(img, aut, hndl, ilkd, fav){ this.image = img; this.author = aut; this.handle = hndl; this.isliked = ilkd; this.favorites = fav; } }
Comments
Post a Comment