У меня есть директива (с локальной областью действия) и контроллер.Если я хочу получить доступ к данным студентов из контроллера в директиву, как мне это сделать?ниже код.Моя цель состоит в том, чтобы построить диаграмму, которая показывает данные о студентах, которые отсутствовали и присутствовали, и когда пользователь нажимает на отсутствующий / присутствующий, я должен иметь возможность показать таблицу с деталями.
JS
app.directive('hcPieChart', function () {
return {
restrict: 'E',
template: '<div></div>',
scope: {
title: '@',
data: '='
},
link: function (scope, element,attrs) {
Highcharts.chart(element[0], {
chart: {
type: 'pie',
spacingTop: 30,
width: 300,
height: 250,
},
title: {
text: ''
},
plotOptions: {
pie: {
allowPointSelect: true,
cursor: 'pointer',
showInLegend: true,
dataLabels: {
enabled: false,
format: '<b>{point.name}</b>: {point.percentage:.1f} %'
},
events: {
click: function(event)
{
how can i access the student details from the controller to this function ? i want to use the click to call a rest service (inside the controller ).
},
series: [{
data: scope.data
}]
});
}
};
})
app.controller('myCtrl', ['$scope','$http','DTOptionsBuilder', 'DTColumnBuilder',function($scope,$http,DTOptionsBuilder, DTColumnBuilder)
{
$scope.showTableDetails=function(x,typeOfData){
$scope.showTableDetailsData="";
$scope.showTableName="";
$scope.checkAnomaly= false;
if(typeOfData==1){
dataCatagory="total";
$scope.checkAnomaly==false;
}else if(typeOfData==2){
dataCatagory="present";
$scope.checkAnomaly==false;
}else if(typeOfData==3){
dataCatagory="absent";
$scope.checkAnomaly==false;
}
$http.get('http://localhost/rest/tripsStatus/studentdetails/'+x.tripDetails.tripId+'/'+dataCatagory+'/am').
then(function(result) {
$scope.showTableDetailsData = result.data.messages[0].data.studentDetails;
$scope.showTableName=x.tripDetails.tripName;
});
HTML
<div ng-app="myApp" ng-controller="myCtrl">
<div ng-repeat="x in data track by $index" style="float:left";>
<div class="wrapper">
<trip-details></trip-details>
<div class="chartdiv">
<hc-pie-chart data="showPieChart(x)"></hc-pie-chart>
</div>
</div>
</div>
</div>