Comments (10)
Hello @beradrian .
I have never worked with ODATA. If you are 100% sure that your resource class name will be used in path, than yes, you can overwrite _getPath
or getPath
methods. Otherwise better to define path for each request separately.
from ngx-resource.
By default, the path will be the class name (or start with it). What's the difference between _getPath
and getPath
? Which one should I override in this case?
from ngx-resource.
And another question - what will be the best way to define the base URL across all resources?
from ngx-resource.
There's also the problem that _getPath
is marked as private.
from ngx-resource.
@beradrian so the best for you will be override getPath
method, not _getPath
.
To define global base URL is better to use static class somewhere in your app component:
ResourceGlobalConfig.url = 'https://api.mydomain.com'
from ngx-resource.
And if I override getPath
can I still use the path property of the annotation?
from ngx-resource.
I have the following
export class ODATAResource<R> extends Resource {
@ResourceAction({
path: '/{!id}'
})
get: ResourceMethod<{id: any}, R>;
getPath(): string | Promise<string> {
return "/" + this.getPlural();
}
private getName() {
return (<any>this).constructor.name;
}
private getPlural() {
return this.getName() + "s";
}
}
@Injectable()
@ResourceParams()
export class UserResource extends ODATAResource<User> {
}
The problem is that when I call userResource.get({id: "1"})
the URL http://localhost/1 gets called instead of http://localhost/Users/1 as I would have expected. Am I missing something?
from ngx-resource.
In your case getPath
is also overridden by method decorator
@ResourceAction({
path: '/{!id}'
})
get: ResourceMethod<{id: any}, R>;
from ngx-resource.
So to resolve that I think better to override getUrl
, which will return full path with your class name. In that case you can decorate methods with path
param.
export class ODATAResource<R> extends Resource {
@ResourceAction({
path: '/{!id}'
})
get: ResourceMethod<{id: any}, R>;
getUrl(): string | Promise<string> {
return super.getUrl() + "/" + this.getPlural();
}
private getName() {
return (<any>this).constructor.name;
}
private getPlural() {
return this.getName() + "s";
}
}
@Injectable()
@ResourceParams()
export class UserResource extends ODATAResource<User> {
}
Final url is created by kind of getUrl() + getPath()
from ngx-resource.
I would have expected that the url/path of the method to be relative to the one of the class, which will also be relative to the global one.
Anyway, wanted to thank you for a great library.
from ngx-resource.
Related Issues (20)
- @ResourceAction decorator doesn't respect "headers" parameter HOT 2
- Migrating to angular 5? HOT 1
- Response Interceptor HOT 1
- then is not a function in IResourceMethodPromise HOT 3
- Abort request in 7.0? HOT 2
- Switching to ResourceCRUDObservable 2x requests HOT 12
- Intercept array response in 7.0 HOT 2
- Promise rejected for resource declared in custom ngModule HOT 2
- Generic ModuleWithProviders get an error HOT 3
- Unable to build with Angular 9 - ResourceModule.forRoot returns a ModuleWithProviders type without a generic type argument. HOT 1
- resultFactory returns wrong value in case of array of numbers in the response
- Support for Angular 10 HOT 4
- Cannot customize the name and type of the id property for CRUD
- How to cancel the request
- Howto retry request HOT 2
- Old deprecated ngx-resource - how to define responseType. HOT 3
- Uploading yaml file
- ResourceAction decorator not working
- Type error after updatin to Angular 15
- Send array of params joined by & HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from ngx-resource.