Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

momentjs causing problems due to bug with $watch in angular.js #344

Closed
etodanik opened this issue Jun 10, 2014 · 2 comments
Closed

momentjs causing problems due to bug with $watch in angular.js #344

etodanik opened this issue Jun 10, 2014 · 2 comments

Comments

@etodanik
Copy link

Before submitting a pull request for this one, I'd like to check out the viability of this being accepted.

If you use momentjs in the filters, hell breaks loose due to a peculiarity of angular.copy, which right now copies the prototype rather than reusing it:
angular/angular.js#3767
angular/angular.js#5063

A slight change to ng-table can prevent moment.js from wearing havoc:

$scope.$watch('params.$params | json', function (newParams, oldParams) {
        $scope.params.settings().$scope = $scope;

        if (!angular.equals(JSON.parse(newParams).filter, JSON.parse(oldParams).filter)) {
            delayFilter(function () {
                $scope.params.$params.page = 1;
                $scope.params.reload();
            }, $scope.params.settings().filterDelay);
        } else {
            $scope.params.reload();
        }
    }, true);

What I'm doing here is watching JSON.stringify-ed params, rather than the objects, to prevent the angular.copy issue from running unlimited refreshes.

I'm not quite sure if this is the kind of change one would like to make in a library, however moment.js is a pretty widely adopted library, and it would make sense to be able to anticipate it's use in filter properties.

@petebacondarwin
Copy link

angular.copy is now fixed in master so perhaps you can close this?

@etodanik
Copy link
Author

correct, thank you very much ! :) you're sort of omnipotent, aren't you?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants