Click here to Skip to main content
15,894,825 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a component which is properly being called from the .ts file but it's still not returning the data.

And have a service

        import {Component} from 'angular2/core'
        import {AuthorServices} from './author.service'
       @Component 
       ({
    selector: 'author',
    template: `
                <h1>Authors</h1>
                    {{title}}
                    <ul>
                        <li ngFor ="#auth of author">
                            {{auth}}
                        </li>
                    </ul>
    `,
    providers: [AuthorServices]})

    export class AuthorComponent{
             title ="Name of Author";
             authors;
             constructor(authorServices : AuthorServices){
             this.authors = authorServices.getAuthor();
            } }

    export class AuthorServices{
    
    getAuthor(): string[]{
        
        return ['Paul','Eva','Nicholas'];
        }}

It should return array along with its title. But I am not sure where it's getting stuck. Please Help!


What I have tried:

I tried changing the tags, checked the directives and also the calls made accross
Posted
Updated 9-Nov-17 18:36pm

1 solution

Please try following and let me know if that doesn't work for you-
HTML
<ul>
   <li *ngFor="let auth of authors">
    {{auth}}
   </li>
</ul>


Why? Because your array name is authors and not author.

Hope, it helps :)
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900