I am creating a basic Todo application in angular2 when I press the add button to send data from parent to child using input. I get no provider for the string! (child-> string), and only the displayed information is shown only in the child class, which means
here is the parent component:
@Component({
selector : 'parent-component',
directives : [child],
template : `
<h1 class= "text-center">ToDo App</h1>
<div class = "form-group">
<lable>Task</lable>
<input type = "text" class = "form-control" #task>
<lable>Detail</lable>
<input type = "text" class = "form-control" #detail >
<button type = "submit" class = "btn btn-default"
(click) = "addtask(task, detail)">Add Task</button>
<child-component *ngFor = "#todo of Array" [taskobject] = "todo">
Loading... </child-component>
</div>
`
})
class parent{
Array : child[];
id : number;
constructor(){
this.Array = [];
}
addtask(task : HTMLInputElement, detail : HTMLInputElement){
this.id = Date.now();
this.Array.push(new child(task.value, detail.value, this.id ));
console.log(Array)
task.value = '';
detail.value = '';
}
And this is a child component:
@Component({
selector : 'child-component',
inputs : ['taskobject'],
template : `
{{taskobject.task}}
{{taskobject.details}}
<button type = "button" class = "btn btn-default"
(click) = "deletetask()">Delete</button>
<button type = "button" class = "btn btn-defualt"
(click) = "updatetask()">Update</button>
`
})
class child{
task : string;
detals : string;
id : number;
constructor(task : string, detail : string, id : number){
this.task = task;
this.detals = detail;
this.id = id;
}
}
source
share