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

Popular posts from this blog

ios - RestKit 0.20 — CoreData: error: Failed to call designated initializer on NSManagedObject class (again) -

laravel - PDOException in Connector.php line 55: SQLSTATE[HY000] [1045] Access denied for user 'root'@'localhost' (using password: YES) -

java - Digest auth with Spring Security using javaconfig -