-
Notifications
You must be signed in to change notification settings - Fork 1
AngularSDK
Michael Rüfenacht edited this page Sep 5, 2019
·
5 revisions
We use a component to generate the Loopback AngularSDKs on the fly and load it into our frontend applications.
The behavior of remote methods in Angular is barely documented. Usually one has do differentiate between method parameters (passed using the url), the body that is sent and the options object.
"methods": {
"translateProperties": {
"accepts": [
{
"arg": "sourceContent",
"type": "object",
"http": {
"source": "body",
},
},
{
"arg": "from",
"type": "string",
"required": true,
"http": {
"source": "path",
},
},
{
"arg": "to",
"type": "string",
"required": true,
"http": {
"source": "path",
},
},
{
"arg": "options",
"type": "object",
"http": "optionsFromRequest",
},
]
}
}
}Basically a remote method attached to an angular resource accepts four parameters:
- The parameters as an object hash e.g.
{ from: 'en-gb', to: 'de-ch' } - The body to be sent e.g.
{ first: 'Hello', second: 'World' } - A success callback
- An error callback
The remote methods furthermore return an object containing a $promise property which can be used to omit the the callbacks. Since we rely on async/await, we omit the cases including callbacks in this documentation.
Ingoring cases having a callback, there are three remaining cases of remote method invocations on resources:
const invocationOnlyWithBody = await myService_MyModel.translateObject(body).$promise;
const invocationOnlyWithParams = await myService_MyModel.translateObject(params).$promise;
const invocationWithBodyAndParams = await myService_MyModel.translateObject(params, body).$promise;