TL:DR - Need to access <ma-watch-list-get> points in a directive controller. I assumed I could just inject $rootScope into the controller, but didn't see it there. Any help appreciated.
I have an maWatchListGet directive on my page which eventually informs an indicator/button directive template with several point properties (see service below):
<div ng-controller = 'PushCtrl as vm'>
<ma-watch-list-get ng-model="indicatorWl" parameters="indicatorWl.parameters" on-points-change="indicatorWl.points = $points" id="wl-indicator-id" watch-list-xid="WL_Indicator"></ma-watch-list-get>
<ma-get-point-value points="indicatorWl.points"></ma-get-point-value>
<push-lamp points="point" pid = "DP_ind_H2OT2"></push-lamp>
</div>
on the way, I need to get the indicatorWl.points into a service to filter and parse out several member values for use in the directive template. My problem is in getting access to the scope that contains the <ma-watch-list-get>, so that I can get it into the service.
...
.directive('pushLamp', function () {
return {
restrict: 'AE',
template: [ '<div class="indicator {{vm.point.color}}"',
'<br/>{{vm.point.name}}<br/>{{vm.point.label}}</div>'
].join(''),
scope: {},
bindToController: {
points: '=',
pid: '@'
},
controller: 'PushCtrl',
controllerAs: 'vm'
};
})
.controller('PushCtrl', ['$log','$timeout','pointService','$scope', function ($log,$timeout,pointService,$scope) {
var vm = this;
vm.point = pointService.getPoint(vm.points,vm.pid); //returns single point object from:
.factory('pointService', ['$filter','$log','$timeout', function ($filter, $log, $timeout) {
var service = {};
function colorVal(num) { //transform number into class name
switch (num) {
case 1:
return 'white';
case 2:
return 'red';
...
default:
return 'off'
}
} //colorVal
service.getPoint = function (points,pid) {
var point = $filter('filter')(points, {xid:pid});
return {
value: point[0].value,
colorClass: point[0].renderedValue,
color: colorVal(point[0].value),
blink: point[0].value % 10,
xid: point[0].xid,
name: point[0].name,
label: point[0].tags.indText
}
};
return service;
}]) //pointService