astronaut1712 / angular2-odoo-jsonrpc

OdooRPC for angular2
21 stars 24 forks source link

Uncaught (in promise): Error: StaticInjectorError[ConnectionBackend]: #10

Closed stevenxvii closed 6 years ago

stevenxvii commented 6 years ago

Hello,

I am experiencing some issues when implementing this, after of all installation, I added to my Ionic project (blank project with home page)

  1. app.module.ts
    • Added:

import { OdooRPCService } from 'angular4-odoo-jsonrpc';

providers: [ ..., OdooRPCService, ... ]

  1. home.ts
    • Added:

import { OdooRPCService } from 'angular4-odoo-jsonrpc';

export class HomePage {

constructor(public navCtrl: NavController, public odooRPC: OdooRPCService) { odooRPC.init({ odoo_server: "http://website", http_auth: "username:password" // optional }); odooRPC.login('database', 'my-username', 'my-password').then(res => { console.log('login success'); }).catch( err => { console.error('login failed', err); }) }

}

But when I run ionic serve, it shows the error

Error: Uncaught (in promise): Error: StaticInjectorError[ConnectionBackend]: StaticInjectorError[ConnectionBackend]: NullInjectorError: No provider for ConnectionBackend! Error: StaticInjectorError[ConnectionBackend]: StaticInjectorError[ConnectionBackend]: NullInjectorError: No provider for ConnectionBackend! at _NullInjector.get (http://localhost:8100/build/vendor.js:1276:19) at resolveToken (http://localhost:8100/build/vendor.js:1564:24) at tryResolveToken (http://localhost:8100/build/vendor.js:1506:16) at StaticInjector.get (http://localhost:8100/build/vendor.js:1377:20) at resolveToken (http://localhost:8100/build/vendor.js:1564:24) at tryResolveToken (http://localhost:8100/build/vendor.js:1506:16) at StaticInjector.get (http://localhost:8100/build/vendor.js:1377:20) at resolveNgModuleDep (http://localhost:8100/build/vendor.js:10937:25) at _createClass (http://localhost:8100/build/vendor.js:10976:29) at _createProviderInstance$1 (http://localhost:8100/build/vendor.js:10948:26) at c (http://localhost:8100/build/polyfills.js:3:19752) at Object.reject (http://localhost:8100/build/polyfills.js:3:19174) at NavControllerBase._fireError (http://localhost:8100/build/vendor.js:48008:16) at NavControllerBase._failed (http://localhost:8100/build/vendor.js:48001:14) at http://localhost:8100/build/vendor.js:48048:59 at t.invoke (http://localhost:8100/build/polyfills.js:3:14976) at Object.onInvoke (http://localhost:8100/build/vendor.js:4979:33) at t.invoke (http://localhost:8100/build/polyfills.js:3:14916) at r.run (http://localhost:8100/build/polyfills.js:3:10143) at http://localhost:8100/build/polyfills.js:3:20242

I tried to fix the error but still not OK,

Would appreciate for any help

hengkyz commented 6 years ago

seems like the error from "ConnectionBackend" you need to add that service to the provider

stevenxvii commented 6 years ago

Hi hengkyz,

Thanks for your prompt reply, Can you show me how? As I know that importing HttpModule will also bring both Http and ConnectionBackend.

Anyway, I tried to add ConnectionBackend as

import { ConnectionBackend } from '@angular/http'; and

providers: [ ..., HttpModule, [ConnectionBackend], ... ]

But still error,

Regards

hengkyz commented 6 years ago

https://stackoverflow.com/questions/40098413/angular-2-no-provider-for-connectionbackend

you need to import it in the app.module instead of add it in the provider

stevenxvii commented 6 years ago

Thanks hengkyz,

After changing to import, it works like a charm

Best regards

stevenxvii commented 6 years ago

Hello hengkyz,

Could you please help me some usage? For example, I want to get all or some records? I tried the following for getting 1 record

odooRPC.call('pos.order', 'read', [1], {}).then(res => { console.log(res) }).catch(err => { console.log(err) });

Thanks in advance

hengkyz commented 6 years ago

yes there is nothing wrong with that code, what is the error message?

stevenxvii commented 6 years ago

Hi, yes, there is no error, I just want to know how to retrieve all records instead of 1 record, can you help?

hengkyz commented 6 years ago

i see, then you need to use "searchread" method instead of read

stevenxvii commented 6 years ago

Hi,

odooRPC.call('pos.order', 'read', [0], {}).then(res => {

returns an empty array, and

odooRPC.call('pos.order', 'read', 0, {}).then(res => {

will return error

TypeError: 'int' object has no attribute 'getitem'

What did I wrong?

hengkyz commented 6 years ago

sorry i edit the comment please read it 1 more time, you should use "searchRead" method instead of read

stevenxvii commented 6 years ago

searchRead is OK, but how can I limit the criteria? For example, what if I want to search for id = 1, 2 (between 1 and 2)?

hengkyz commented 6 years ago

i dont get it, can you make an example in odoo way, i can tell you how to do it in angular

stevenxvii commented 6 years ago

Hello,

I checked the code and figured out how to implement,

To update what I mean, searchRead takes 4 args (model, domain, fields, limit) and the following code will retrieve all records in the model 'pos.order'

odooRPC.searchRead('pos.order', {}, {}, 0).then(res => {

whereas, the following code will retrieve record with id = 1

odooRPC.searchRead('pos.order', [ [ 'id', '=', 1 ] ], {}, 0).then(res => {