currently able pass value angularjs service angular controller, doing calculation in 1 controller , want pass controller , can please me
service name : detailservice
controller 1 : fromservice
controller 2 : barctrl
- in below code getting values detailservice fromservice controller
- and in fromservice controller evaluating value array $scope.valuessendtograph
i wanted send $scope.valuessendtograph barctrl controller , can please me , how approach problem
angularjs code
var app = angular.module('myapp', ["chart.js"]); app.service('detailservice', function($http, $filter, $q) { return { getinfo: function() { return $http({ method: 'post', url: 'myjson.json' }).then(function(response) { msoresponsearray = response.data; var passbycompanyarray = []; var failbycompanyarray = []; var wipbycompanyarray = []; var releasenamearray = []; var totalcountarray = []; var fullarray = []; msoresponsearray.foreach(function(item) { releasenamearray.push(item.executions[0].cyclename); }); msoresponsearray.foreach(function(item) { /* filtering items passed*/ passbycompany = $filter('filter')(item.executions, function( inputs) { if ((inputs.executedby == 'a' || inputs.executedby == 'b' || inputs.executedby == 'c' || inputs.executedby == 'd') && inputs.executionstatus == '1') return inputs; }); passbycompanyarray.push(passbycompany.length); //passbycompanyarray.unshift(item.executions[0].cyclename); failbycompany = $filter('filter')(item.executions, function( inputs) { if ((inputs.executedby == 'a' || inputs.executedby == 'b' || inputs.executedby == 'c' || inputs.executedby == 'd') && inputs.executionstatus == '2') return inputs; }); failbycompanyarray.push(failbycompany.length); //failbycompanyarray.unshift(item.executions[0].cyclename); wipbycompany = $filter('filter')(item.executions, function( inputs) { if ((inputs.executedby == 'a' || inputs.executedby == 'b' || inputs.executedby == 'c' || inputs.executedby == 'd') && inputs.executionstatus == '3') return inputs; }); wipbycompanyarray.push(wipbycompany.length); //wipbycompanyarray.unshift(item.executions[0].cyclename); }); return $q.when([releasenamearray, passbycompanyarray, failbycompanyarray, wipbycompanyarray]); }) } } });
app.controller('fromservice', function($scope, detailservice) { detailservice.getinfo().then(function(data) { $scope.newvalue = data; $scope.releasename = data[0]; $scope.passcount = data[1]; $scope.failcount = data[2]; $scope.wipcount = data[3]; function sumvalue(arr) { var total = 0; arr.foreach(function(element) { total += element; }) return total; } var sumpasscount = sumvalue($scope.passcount); var sumfailcount = sumvalue($scope.failcount); var sumwipcount = sumvalue($scope.wipcount); $scope.valuessendtograph = [sumpasscount, sumfailcount, sumwipcount]; console.log($scope.valuessendtograph); $scope.fullarray = $scope.releasename.map(function(item, i) { return { releasename: item, passcount: $scope.passcount[i], failcount: $scope.failcount[i], wipcount: $scope.wipcount[i] } }); console.log($scope.fullarray); }); });
app.config(function(chartjsprovider) { // configure charts chartjsprovider.setoptions({ colors: ['#803690', '#00adf9', '#dcdcdc', '#46bfbd', '#fdb45c', '#949fb1', '#4d5360'], defaultfont: 've' }); // configure doughnut charts chartjsprovider.setoptions('doughnut', { cutoutpercentage: 60 }); chartjsprovider.setoptions('bubble', { tooltips: { enabled: false } }); });
app.controller('barctrl', function($scope) { $scope.labels = ['passed', 'failed', 'wip']; $scope.series = ['regression']; $scope.data = [ $scope.valuessendtograph ]; });
i doing calculation in 1 controller , want pass controller
i recommend move calculations service. controller responsible bind data view.
i wanted send $scope.valuessendtograph barctrl controller
since service singleton, can store valuessendtograph
in service , load other controller
if still want send valuessendtograph
content controller controller , have same level, can use $broadcast
on root level, example:
$rootscope.$broadcast('values', $scope.valuessendtograph);
in barctrl
call:
$scope.$on('values', function(event, data) { $scope.valuessendtograph = data; });
be sure call $scope.$on('values',
before $rootscope.$broadcast
Comments
Post a Comment