我使用几个问题的解决方案使用 highchart.js 渲染了一个图表。我了解指令的基本用法。但是,在 highchart.js 的情况下,我不太明白这里的代码:
app.directive('highchart', function () {
var direc = {};
var link = function (scope, element, attributes) {
scope.$watch(function () {
return attributes.chart;
}, function () {
var charts = JSON.parse(attributes.chart);
$(element[0]).highcharts(charts);
})
}
direc.restrict = 'E';
direc.link = link;
direc.template = '<div></div>';
//the replace method replaces the content inside the element it is called
direc.replace = true;
direc.scope = {};
return direc;
})
图表属性将接受图表属性的 JSON 数组。
有人可以解释函数内部发生了什么吗?感谢您的阅读。