指令html的动态div id

时间:2017-05-22 07:46:43

标签: javascript html angularjs angularjs-directive amcharts

我在指令模板中使用动态div id来渲染图形时遇到问题。我得到的错误是

  

无法设置属性&inner;内部HTML'为null

我的template.html

<div id="{{title}}" style="height: 40vh;"></div>

该指令只是在给定的div id

上呈现图形
link: function (scope, element, attrs) {
        let chart = AmCharts.makeChart(scope.title, {
          type: "stock",
          theme: "light",
          dataSets: [scope.data.dataset],
          panels: [{
            showCategoryAxis: false,
            recalculateToPercents: "never",
            title: scope.data.title,
            valueAxes: [{
              title:  scope.data.type,
              titleFontSize: 10,
              titleBold: false
            }],
            stockGraphs: [{
              id: "g1",
              valueField: "value",
              comparable: true,
              bullet: "round",
              bulletBorderColor: "#FFFFFF",
              bulletBorderAlpha: 1,
              balloonText: "[[title]]: <b>[[value]]</b>",
              compareGraphBalloonText: "[[title]]: <b>[[value]]</b>",
              compareGraphBullet: "round",
              compareGraphBulletBorderColor: "#FFFFFF",
              compareGraphBulletBorderAlpha: 1
            }],
            stockLegend: {
              periodValueTextRegular: "[[value.close]]"
            },
          }],
          panelsSettings: {
            mouseWheelZoomEnabled: true,
            marginLeft: 60
          },
          valueAxesSettings: {
            axisAlpha: 1,
            gridThickness: 0,
            axisThickness: 1,
            inside: false
          },
          categoryAxesSettings: {
            minPeriod: "ss"
          },
          chartScrollbarSettings: {
            graph: "g1",
            usePeriod: "10mm",
            updateOnReleaseOnly: false
          },
          chartCursorSettings: {
            cursorPosition: "mouse"
          },
          periodSelector: {
            dateFormat: "YYYY-MM-DD JJ:NN:SS",
            periods: [{
              period: "hh",
              count: 1,
              label: "1 hour"
            }, {
              period: "hh",
              count: 2,
              label: "2 hours"
            }, {
              period: "hh",
              count: 5,
              label: "5 hour"
            }, {
              period: "hh",
              count: 12,
              label: "12 hours"
            }, {
              period: "MAX",
              label: "MAX"
            }]
          }
        });

      }

任何人都知道如何解决这个问题,提前谢谢。

1 个答案:

答案 0 :(得分:0)

尝试使用ng-attr-在div上设置ID。例如:<div ng-attr-id="title" style="height: 40vh;"></div>