Hi

I am new to angular 2

I have used the following code to get the values from my controller


app.component.ts

import { Component,OnInit, Injectable, Inject} from 'angular2/core';
import { NgIf, NgFor } from 'angular2/common';
import {Http, Response, HTTP_PROVIDERS, Headers, RequestOptions} from 
'angular2/http';
import { TodoItem } from './model';
import { DataService } from './data.service';
import { Observable } from 'rxjs/Observable';


@Component({
    selector: 'angularjs2demo',  
    template: `    
<ul>
    <li *ngFor="let person  of people">
    
      {{person.name}}
    
     {{person.city}}
    </li>


  </ul>

              `,

    providers: [DataService]

})


export class AppComponent implements OnInit
{
    people: TodoItem[];

    constructor(private dataService: DataService) { }

    ngOnInit() {
        // Load comments
        this.loadComments()
    }

    loadComments() {
        // Get all comments
        this.dataService.getComments()
            .subscribe(
            people => this.people = people, //Bind to view
            err => {
                // Log errors if any
                console.log(err);
            });
    }
   

}

dataservice.ts

import { Http, Jsonp, Response, Headers, RequestOptions } from 
'angular2/http';
import { Injectable, Inject } from  'angular2/core';
import { TodoItem  } from './model';
import { Observable } from 'rxjs/Observable';
import 'rxjs/add/observable/forkJoin';

//const PEOPLE: TodoItem[] = [
//    { name: 'Visa', city: 'Coimbatore' },
//    { name: 'Divya', city: 'Chennai' },
//    { name: 'Bharathi', city: 'Coimbatore' },
//];

//@Injectable()
//export class DataService {
//    getAll(): TodoItem[] {
//        return PEOPLE;
//    }
//}

@Injectable()
export class DataService {

    constructor(private http: Http) { }

    getComments(): Observable<TodoItem[]> {       
        return this.http.get('http://localhost:59024/api/User/GetUsers')
            .map((res: Response) => res.json());         
         

    }


}

model.ts

//export interface TodoItem {   
   
//        name: string;
//        city: string;
   
//}

export class TodoItem {
    constructor(     
        public name: string,
        public city: string
    ) { }
}

Please guide me for the above issue

when i call constant data its working fine .but using http get it is not 
working.

-- 
You received this message because you are subscribed to the Google Groups 
"Angular and AngularJS discussion" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/angular.
For more options, visit https://groups.google.com/d/optout.

Reply via email to