ionic-letter-avatar-selector icon indicating copy to clipboard operation
ionic-letter-avatar-selector copied to clipboard

getData()

Open adyba opened this issue 8 years ago • 0 comments

Thank you for the last commit. I really love the finishOnStateChange feature !! I don't know if it is just the last version but now it crashes on a simple string.

<ion-item class="item-remove-animate"
    letters-of="{{chat.name}}"
    item="{{chat.id}}"   // Once chat.id == 'KLN3hiknhj44' it errors out.
    ...

The getData() function (line 501) uses JSON.parse() with a function that is trying to handle the date (described as an text) but errors on a simple string. Be honest I have failed to fix the JSON.parse mess but there could be a easier way.

self.getData = function() {
  data.forEach(function(value, index) {
    var result = null;
// if value is date (as an text) it returns Date(value). It handles more date/text formats but it may not work in IE<9
    result = (angular.isString(value) && (((new Date(value)).toString() !== "Invalid Date") ? true : false)) ? new Date(value) : value;
// if value is "text" it literally returns ""text"" 
    result = (angular.isString(result)) ? angular.toJson(result) : result;
// angular.fromJson() is basically an equivalent of JSON.parse()
    data[index] = angular.fromJson(result);
  });
};

If the first condition fires the second gets false. Any other values should be OK with angular.fromJson(). Well I haven't tested weird values like null, undefined, but you got the idea.

adyba avatar May 31 '16 20:05 adyba