Chandu
Chandu

Reputation: 127

Syntax to update a field in strongloop using angular js client

I am using below code to update strongloop model from angularJS client.

Customers.update({access_token : localStorage.getItem("accessToken")},{id: localStorage.getItem("userId"), lastlogin : localStorage.getItem("signinTime")
        }, function(success) {
            console.log(success);
            defer.resolve(success);
        }, function(error) {
            console.log(error);
            defer.reject(error);
        }).$promise;

URL is:

http://localhost:3000/api/customers/update?access_token=EbgIvaRu0141yXB7QeK7JPqWSFr5dwlQQBWnAxcUnOLBmWhVq8IFmhEuqgxVz2xl&id=55f814c414009bf51bdd7633

Here why "update" is appending in url? Please tell me the correct syntax.

Upvotes: 1

Views: 364

Answers (2)

Mouneer
Mouneer

Reputation: 13489

For those who may face that problem, You can try $resource instance's $save() method.

// Create or use your current instance
var customer = new Customer({name: 'name'});
customer.$save(null,function(customer){
    defer.resolve(success);
});

Upvotes: 0

Chandu
Chandu

Reputation: 127

I found, why update is appending in url. In lb-services.js, updateAll method appending "update" in the url.

Solution to update strongloop's model properties from angularjs client using restapi is,

Customers.prototype$updateAttributes({access_token : localStorage.getItem("accessToken")}, {id : localStorage.getItem("userId"), lastlogin: localStorage.getItem("signinTime")}
            , function(success) {
                defer.resolve(success);
            }, function(error) {
                defer.reject(error);
            }).$promise;

Upvotes: 2

Related Questions