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

关于ESlint校验 angular/on-watch 如何fix问题 #19

Open
hjzheng opened this issue Jul 25, 2016 · 0 comments
Open

关于ESlint校验 angular/on-watch 如何fix问题 #19

hjzheng opened this issue Jul 25, 2016 · 0 comments

Comments

@hjzheng
Copy link
Member

hjzheng commented Jul 25, 2016

7:3 error The "$watch" call should be assigned to a variable, in order to be destroyed during the $destroy event angular/on-watch

(function() {
    angular.module('app').run(run);

    run.$inject = ['$rootScope', '$location', '$http'];

    function run($rootScope, $location, $http) {
        var callback = $rootScope.$watch(function() {
            return $location.search();
        }, function(newValue) {
            if (newValue.token) {
                $http.defaults.headers.common.token = newValue.token;
            }
        });

        $rootScope.$on('$destroy', callback);
    }
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant