Simple example: From my server, I get an array of friends. I want to create a ‘Friend’ class with attributes like ‘name’ and methods like ‘sendMessage(msg)’. How do I accomplish this using es6 classes?
I have tried creating a simple injectable class, but this gives me the error: “Uncaught TypeError: Cannot read property ‘getOptional’ of undefined.” The error goes away if I change the constructor to constructor(){… but that defeats the purpose.
import {Injectable,Injector} from 'angular2/core';
@Injectable()
export class Friend{
constructor(name){
this.name = name
}
greet(){
console.log("My name is " + this.name);
}
}
How can I use the constructor in a provider / other class? I’ve tried injecting it like a normal data provider and including it in the app.js providers array etc, but I can’t get it to work like I expect.