Search code examples
javascriptangularjsangularjs-service

AngularJs service methods to accept object OR multiple parameters - Which one is best practice


What is the best practice while creating Angular JS service methods. To accept multiple parameters or as a object.

var getMessages = function (appid, userId,limit) {
    var data = {
        "appid": appid,
        "userId": userId,
        "limit": limit,
    }
    // Call rest api using data variable
}

OR

var getMessages = function (data) {
// Call rest api using data variable
}

Solution

  • This is best practice ever....

    var getMessages = function (appid, userId,limit) {
        var data = {
            "appid": appid,
            "userId": userId,
            "limit": limit,
        }
        // Call rest api using data variable
    }