bahaaldine / angular-csv-import

Angular component that lets you import and convert CSV file to JSON
MIT License
150 stars 89 forks source link

Header varible is flipped each file change. #41

Open Scrambles56 opened 8 years ago

Scrambles56 commented 8 years ago

When ever you change CSV file, the Library actually changes the users Header configuration. The $scope.$watch in the following code should really NEVER trigger, as this is a user configuration, and this configuration should be considered as a non-mutable ruleset, but every time you change file.

    var csvShouldUseHeader = false;
    $scope.csv = {
        separator: ",",
        header: csvShouldUseHeader,
        accept: '.csv'
    };

    $scope.$watch("csv.header", function(newValue){
        if(newValue !== csvShouldUseHeader){
            //This log shows that some bad behaviour is happening from with the library.
            console.log("We are trying to change the header property to something we didn't specify", newValue);
            //The following line corrects the header property back to what we have specified. A user fix to the library that really shouldnt be needed.
            $scope.csv.header = csvShouldUseHeader;
        }
    });