Для компонента task
используйте одностороннюю привязку с '<'
для входов и привязку выражений с '&'
для выходов:
app.component("task", {
bindings: { item: '<',
backTask: '&',
advanceTask: '&',
deleteTask: '&'
},
controller: function() {
this.backClick = (event) => this.backTask({$event: event});
this.advanceClick = (event) => this.advanceTask({$event: event});
this.deleteClick = (event) => this.deleteTask({$event: event});
},
template:
`<div>
<p class="assignment">{{ $ctrl.item.Assignment }}</p>
<p class="assignment">{{ $ctrl.item.Assignee }}</p>
<button ng-click="$ctrl.backClick($event)"><i class="fas fa-arrow-left"></i></button>
<button ng-click="$ctrl.advanceClick($event)"><i class="fas fa-arrow-right"></i></button>
<button ng-click="$ctrl.deleteClick($event)"><i class="fas fa-trash-alt"></i></button>
</div>`
});
Аналогично для компонента taskList
:
app.component("taskList", {
bindings: { status: '<',
tasks: '<',
backTask: '&',
advanceTask: '&',
deleteTask: '&',
},
controller: function() {
this.backClick = (event,task) => backTask({$event:event, $task:task});
this.advanceClick = (event,task) => advanceTask({$event:event, $task:task});
this.deleteClick = (event,task) => advanceTask({$event:event, $task:task});
},
template:
`<div id="{{ $ctrl.status }}" class="col-md-4 taskList">
<ul class="list-group">
<li class="list-group-item flex-column">To Do</li>
<li ng-repeat="task in $ctrl.tasks | filter:{Status: 0}" class="list-group-item list-group-item-danger">
<task
item="task"
back-task="$ctrl.backClick($event,task)"
advance-task="$ctrl.advanceClick($event,task)"
delete-task="$ctrl.deleteClick($event,task)">
</task>
</li>
</ul>
</div>`
});
Использование:
<task-list
status="vm.todo"
tasks="vm.tasks"
back-task="vm.backTask($event,$task)"
advance-task="vm.advanceTask($event,$task)"
delete-task="vm.deleteTask($event,$task)">
</task-list>
Для получения дополнительной информации см. AngularJS Developer Guide - Архитектура приложений на основе компонентов .