I have problem with this Angular 2 TS JSONs. I was programing AngularJS in the past but now i am trying Angular 2 and TS . I can't understend how the Json response working here when i am trying to show them on view. I know that this type of show one value in selector opiton is wrong dont worry about it.
<tr *ngFor="let task of tasks;let myIndex = index">
<th> {{myIndex+1}}</th>
<td>{{task.title}}</td>
<td>{{task.CreateDate}}</td>
<td>{{task.CurentMoney}}</td>
<td>
<select class="form-control" id="sel1">
<option>{{ task.History.month}}</option>
</select>
</td>
<td>
Somthing like Task maping class .
export class Task{
_id:string;
title: string;
CreateDate: string;
CurentMoney: number;
isDone: boolean;
History: { month: string, monthMoney:number}[];}
Controler:
import { Component } from '@angular/core';
import {TaskService} from '../../services/task.service';
import {Task} from '../../../Task';
@Component({
moduleId: module.id,
selector: 'tasks',
templateUrl: 'tasks.component.html'
})
export class TasksComponent {
bankName: string;
tasks: Task[];
title: string;
CreateDate: string;
CurentMoney: number;
constructor(private taskService:TaskService){
this.taskService.getTasks()
.subscribe(tasks => {
this.tasks = tasks;
});
}
testObj(){
console.log(this.tasks);
}...}
Servivce:
import {Injectable} from '@angular/core';
import {Http, Headers} from '@angular/http';
import 'rxjs/add/operator/map';
import {Task} from "../../Task";
@Injectable()
export class TaskService{
constructor(private http:Http){
console.log('Task Service Initialized...');
}
getTasks(){
return this.http.get('/api/tasks')
.map(res => <Task[]>res.json());
}
When I call testobj() i have right console output json, but on the view i can't do task.History.month for example.