angularjs - How do I consume another component's property value in Angular 2? -


i have data in component:

@injectable() export class contactsdata {      public contacts: contact[] = [         { id: "1", firstname: "maxxx", lastname: "smith", email: "max@gmail.com" },         { id: "2", firstname: "chris", lastname: "raches", email: "chris@gmail.com" },         { id: "3", firstname: "michael", lastname: "alloy", email: "michael@gmail.com" },         { id: "4", firstname: "john", lastname: "doe", email: "john@gmail.com" },         { id: "5", firstname: "jenny", lastname: "doe", email: "jenny@gmail.com" }     ]; 

i'm trying access service, "cannot find name 'contacts'":

import {contactsdata} "./data"; import {contact} "./contact";  @injectable() export class contactservice{   getcontacts(){       return promise.resolve(contactsdata.contacts); // error here   } 

i've skipped step don't understand - please point me in right direction...

you need inject contactsdata in contactservice.

@injectable() export class contactservice {   constructor(private data: contactsdata) {}    getcontacts() {     return promise.resolve(this.data.contacts);    } } 

Comments

Popular posts from this blog

asynchronous - C# WinSCP .NET assembly: How to upload multiple files asynchronously -

aws api gateway - SerializationException in posting new Records via Dynamodb Proxy Service in API -

asp.net - Problems sending emails from forum -