asafdav / ng-csv

Simple directive that turns arrays and objects into downloadable CSV files
MIT License
573 stars 215 forks source link

Our function attached to the filename attribute gets called continuously #181

Closed leongaban closed 7 years ago

leongaban commented 7 years ago

Markup, note that vh.shareOptions[0] is default so the ng-if with the CSV download button shows up by default:

<section class="export-data-popover" ng-show="vh.chartShareModal">
    <header><h1>Export chart or CSV</h1></header>
    <div class="select-style">
        <select ng-model="vh.displayType" ng-change="vh.toggleDisplayType(vh.displayType)" ng-options="option.name for option in vh.shareOptions">
        </select>
    </div>

    <div ng-if="vh.displayType == vh.shareOptions[0]">
        <p class="csv-directions">Select time interval:</p>
        <div class="granularity">
            <ul>
                <form>
                    <div class="fl">
                        <input type="radio" name="radio" id="radio1" class="radio" ng-model="vh.granularity" value="day" checked/> Day
                    </div>
                    <div class="pl10">
                        <input type="radio" name="radio" id="radio2" class="radio" ng-model="vh.granularity" value="week"/> Week
                    </div>
                </form>
            </ul>
        </div>
        <button class="btn-green-filled" ng-csv="vh.downloadCsv()" filename="{{ vh.csvFilename() }}">Download CSV</button>
    </div>

        <div ng-if="vh.displayType == vh.shareOptions[1]">
            <button class="btn-green-filled" ng-click="vh.downloadChart()">Download Chart</button>
        </div>
    </section>
const csvFilename = () => {
    console.log('csvFilename...')
    return 'Hello World';
};

Screenshot of multiple calls: http://i68.tinypic.com/15s1xlg.jpg

leongaban commented 7 years ago

Note! Just fixed this 50%.

We changed the ng-show at the top of the main section to:

<section class="export-data-popover" ng-if="vh.chartShareModal == true">

So we no longer get the multiple calls, however if you open the dropdown, then the bug happens again. It happens with the dropdown is open as well as when you just move the mouse over our app, hovering over things (with ng-mouseenter and ng-mouseleave).

Is there some kind of AngularJS markup $scope.$watch thingy that is triggering some markup digest cycle?