Angularjs 如何将角度变量传递给另一个角度谷歌图表函数(角度指令)
有人能帮我把角度变量传递给GoogleChart函数吗?这个函数和Angular指令存在于同一个Java脚本中 我还想加载Google图表,只有在传递了这些值之后才能加载。我刚刚读到一些他们提到的问题,比如Promises,我如何在这里使用 Java脚本 在下面的代码中,我想将角度变量openCount、closedCount传递给Google图表函数,就像Angular JS一样 在上面的演示中,我正在硬编码这些值Angularjs 如何将角度变量传递给另一个角度谷歌图表函数(角度指令),angularjs,angularjs-scope,angular-promise,google-visualization,Angularjs,Angularjs Scope,Angular Promise,Google Visualization,有人能帮我把角度变量传递给GoogleChart函数吗?这个函数和Angular指令存在于同一个Java脚本中 我还想加载Google图表,只有在传递了这些值之后才能加载。我刚刚读到一些他们提到的问题,比如Promises,我如何在这里使用 Java脚本 在下面的代码中,我想将角度变量openCount、closedCount传递给Google图表函数,就像Angular JS一样 在上面的演示中,我正在硬编码这些值 "rows": [ {c: [ {v
"rows": [
{c: [
{v: "Defect Opened"},
{v:1}
]},
{c: [
{v: "Defects Closed"},
{v: 2}
]
现在,我想传递控制器下面的值,而不是硬编码值。我如何实现这一点[需要进行哪些修改]
var app = angular.module('defectApp', ["ngTable"]);
app.controller('defectController', [
'$scope',
'$http',
function($scope, $http) {
$http({method: 'POST', url: '/angular/defect/defect.php'}).success(function(response) {
$scope.post = response;
console.log(response);
var openCount = $filter('filter')(response.data, {status: 'Open'}).length,
closedCount = $filter('filter')(response.data, {status: 'Closed'}).length,
assignedCount = $filter('filter')(response.data, {status: 'Assigned'}).length;
console.log(openCount);
})
},
]);
一种选择是引入一种新的方法,并将从
defectController
获取数据的方法投入使用:
.service('defectService', function ($http, $filter) {
return {
getInfo: function () {
return $http({ method: 'POST', url: '/angular/defect/defect.php' })
.then(function (response) {
return {
"openCount": $filter('filter')(response.data, { status: "Open" }).length,
"closedCount": $filter('filter')(response.data, { status: 'Closed' }).length,
"assignedCount": $filter('filter')(response.data, { status: 'Assigned' }).length
}
});
}
};
})
然后注入defectService
服务信息图表控制器。检索数据后,修改图表控制器以绘制图表:
.controller("chartCtrl", function ($scope, defectService) {
defectService.getInfo()
.then(function (info) {
console.log(info);
$scope.drawChart(info);
});
$scope.drawChart = function (info) {
//code is omitted for clarity..
};
});
当您调用
drawSarahChart
时,我想在将值分配给openCount之后调用,closedCount
在openCount
和closedCount
被分配后,你不能将openCount
和closedCount
传递给controller
中的drawSarahChart
中的drawSarahChart
吗); // 加载图表时,为Sarah的比萨饼绘制饼图。google.charts.setOnLoadCallback(drawSarahChart)代码>工作起来像一个符咒,解释得很好,感谢演示:)我发现我的缺陷有点小麻烦。json你能帮我解决这个{“数据”:[{“类型”:“缺陷”,“id”:1,“用户-01”:“约翰”,“状态”:“关闭”,“严重性”:“1-紧急”},{“类型”:“缺陷”,“id”:4,“user-01”:“John”,“status”:“Closed”,“severity”:“4-Medium”},{“type”:“defect”,“id”:5,“user-01”:“John”,“status”:“Open”,“severity”:“4-Medium”}]}
这是我的缺陷的真实结构。json,下面是一个示例。关键点:$filter
函数需要第一个参数的数组,它应该是response.data.data
,因为response.data
对应于响应体和data
根元素