【发布时间】:2016-05-17 13:21:44
【问题描述】:
我是 Angular 新手,在需要帮助时遇到以下问题。 我正在使用角度图表指令http://jtblin.github.io/angular-chart.js/ 来构建图表板。我得到了以下场景:
我有一个指令,一个视图和一个输入代码在这里关联的控制器。 在控制器内部应该有一个数组 charts[] 保存对象。 这些对象应该与图表指令双向绑定。 这样做的适当方法是什么?我将动态地对我的图表进行 bild,而不需要为每个图表附加任何控制器。这可能吗?
reportView.html
<div ng-repeat="c in charts">
<chart></chart>
<div>
reportViewController.js
angular.module('app').controller('reportViewController', reportViewCtrl);
reportViewCtrl.$inject = ['$scope', '$log', 'RefinerService', 'appConfig'];
function reportViewCtrl($scope, $log, RefinerService, appConfig) {
$scope.charts = [];
var chart = {
ID: 1
, Visible: true
, Type: "chart-line"
, Data: [
[65, 59, 80, 81, 56, 55, 40]
, [28, 48, 40, 19, 86, 27, 90]
]
, Labels: ['2006', '2007', '2008', '2009', '2010', '2011', '2012']
, Series: ['Product A', 'Product B']
}
$scope.charts.push(chart);
}
chartTemplate.html
<div class="chart-container" flex>
<canvas class="chart {{c.Type}}"
data="{{c.Data}}"
labels="{{c.Labels}}"
series="{{c.Series}}">
</canvas>
</div>
directive.js
angular.module('app').directive('chart', function () {
return {
restrict: 'E',
templateUrl: 'templates/chartTemplate.html',
scope: {
id: '@id',
type: '@type'
}
};
});
帮助将不胜感激!干杯菲利普
【问题讨论】:
标签: angularjs charts ng-repeat directive