Search code examples
javascriptangularjsangular-promisejslint

How to resolve bad property name $promise error in JSlint


I am getting a JSLint error Bad property name '$promise'. I use AngularJS $resource to save the data. How can I fix the issue?

My code is below:

$ngUser.factory("$userService", [
    "$resource",
    function ($resource) {
        return {
            user: $resource('api/user/', {
                id: '@id'
            }, {
                save: {
                    method: "POST",
                    isArray: false
                }
            })
        };
    }
]);

And I am using the service as:

user = $userService.user.save({
    name: "George"
});
user.$promise.then(function (data) {
    console.log(data);
});

Thanks.


Solution

  • JSLint checks for properties which starts with $ sign. Since most of the frameworks use $ sign as a naming convention for built-in services, it can be ignored.

    If you don't want to ignore it, you can use //noinscpetion JSLint in Webstorm or ignore the block of code using JSLint as following:

    /*ignore jslint start*/
    // block of code
    /*ignore jslint end*/