Skip to Content
เมนู
คุณต้องลงทะเบียนเพื่อโต้ตอบกับคอมมูนิตี้
คำถามนี้ถูกตั้งค่าสถานะ
1 ตอบกลับ
2082 มุมมอง

Hi,


Everything is in the title, when i use "useService" I have this error message

Uncaught (in promise) TypeError: right-hand side of 'in' should be an object, got undefined



This is my component code :

/** @odoo-module **/

import { useState, Component } from "@odoo/owl";
import { useService } from "@web/core/utils/hooks";

export class my_comp extends Component {
static template = "eggs_js.template";

setup() {
const rpt = useService("rpc");

this.state = useState({ value: 0 });
}

async ask_value() {
this.state.value++
}
}


And this is my assets in my manifest


'assets': {
'eggs_js.frontend': [
("include", 'web.assets_frontend'),
'eggs_js/static/src/playground.xml',
'eggs_js/static/src/front/**/*',
],
}

Thank you for the help !
อวตาร
ละทิ้ง
ผู้เขียน คำตอบที่ดีที่สุด

I found why i had this error message. I did'nt put environement when i mount my main component.

before, i had this code to mount my component :

owl.whenReady( () => {
mount(Playground, document.body, { templates, dev: true});
});

But i need to add the environement :

import { mount, useEnv } from "@odoo/owl"; //to import the useEnv

owl.whenReady( () => {
const env = makeEnv();
// put things into the env
mount(Playground, document.body, { templates, dev: true, env });
});

After searching into the odoo code, I found this file :

odoo/addons/web/static/src/legacy/js/public/public_env.js


It contain a default env this all services.


So, my code became :


owl.whenReady( () => {
const env = require("web.public_env");
// put things into the env
mount(Playground, document.body, { templates, dev: true, env });
});

I hope this will help someone,


Regard

อวตาร
ละทิ้ง
Related Posts ตอบกลับ มุมมอง กิจกรรม
1
มิ.ย. 25
391
1
มิ.ย. 25
336
1
พ.ค. 25
936
0
มี.ค. 25
538
1
ธ.ค. 24
3275