Integration with Angular
pachu4u opened this issue · comments
Hi,
I wanted to integrate this with Angular and I have gone ahead and installed the package.
In my angular service I have imported it as below
import { Bodybuilder } from 'bodybuilder';
and the object is injected in constrictor of the service
constructor(private http: HttpClient, private bodybuilder: Bodybuilder) {
}
But for some reason it is not able to create a object of the bodyBuilder
Any advise on how it can be fixed a example for angular would really help.
Regards
@pachu4u I am not experienced with Angular but what is the error you are getting? Can you show the code where you actually try to create the bodybuilder query?
@pachu4u I am not experienced with Angular but what is the error you are getting? Can you show the code where you actually try to create the bodybuilder query?
It can not DI BodyBuilder Object as it is an interface.
I tried import * as bb from bodybuilder.
and use the function directly. like so. bodybuilder(). But says the function is not found at run time.
filters.forEach((filter) => { switch (filter.type) { case 'freetext': if (filter.filteredValue) { if (filter.condition === 'includes') { bodybuilder().addQuery('match', filter.field, filter.filteredValue); } else { bodybuilder().notQuery('match', filter.field, filter.filteredValue); } } break; } });
Just a comment, but I have an Angular project, but I don't expose Elasticsearch to the client. That seems like a huge security problem. I use a backend API for ES queries. Even if I could block writes, I would not want a client to crawl all the data.
…
We eventually plan to wrap our ES with an API with authorisation. But do you see a risk in exposing bodybuilder in client. I was thinking we could get the payload (body) properly structured and then make a call to custom API.
But thanks. I think it would be easy to wrap this into a node based cloud function.
Using typescript, you can go for the commonjs compat way of importing bodybuilder
import bodybuilder = require('bodybuilder')
Nowadays with Angular 10, getting:
WARNING in blahblahblah.ts depends on 'bodybuilder'. CommonJS or AMD dependencies can cause optimization bailouts.
For more info see: https://angular.io/guide/build#configuring-commonjs-dependencies
using import * as bodybuilder from 'bodybuilder';
any plausible way to fix this?