justgage no element with id 0 angular js

633 views Asked by At

I wrote a directive to JustGage plugin as follows.

function justGage() {
        return {
            restrict: 'E',
            replace: true,
            scope: {
                id: '@',
                value: '='
            },
            template: '<div id="{{id}}" class="200x160px" style="margin-top: 5vh"></div>',
            link: function ($scope, $element) {

                var g = new JustGage({
                    id: $scope.id,
                    value: $scope.value,
                    min: 0,
                    max: 100,
                    minLabelMinFontSize: 15,
                    maxLabelMinFontSize: 15,
                    valueMinFontSize: 40,
                    valueFontColor: '#ededed'
                });
            }
        };
    }

In my controller I assign values to id and gauge value

$element.id = "gauge";
$element.value = $scope.data;

My html is as follows.

<just-gage></just-gage>

Then I get an error as "justgage : no element with id 0". In my directive I added the same id to both template and JustGage object. How can I solve this issue to render the gauge?

1

There are 1 answers

0
devqon On

You create a new child scope in your directive, so it doesn't know of the id and value you assigned in the controller.

You can do something like this:

link: function ($scope, $element, $attrs) {

    var g = new JustGage({
        id: $attrs.id,
        value: $attrs.value,
        // ..
    });

}