How to handle empty string parameters in angularjs?

I have a request for my $ resource like so:

        lastName: vm.lastName,
        pageSize: vm.pagingData.pageSize,
        pageNumber: vm.pagingData.pageNumber
    function(data) {
        vm.totalItems = data.totalItems;
        vm.totalPages = data.totalPages;
        vm.pageNumber = data.pageNumber;
        vm.users = data.items;


This works fine until vm.lastName is empty. When it's empty I see the url lastName = & page number ... etc. I am getting this response from my api 2 controller even though lastName is an optional parameter.

{"message": "Request invalid.", "modelState": {"lastName.String": ["Required value, but was not in the request." ]}}

This seems like a silly question, but I can't figure out how to leave a parameter in a request in angularjs if it's empty. Thank!


source to share

All Articles