تخطي للذهاب إلى المحتوى
القائمة
لقد تم الإبلاغ عن هذا السؤال
1 الرد
2074 أدوات العرض

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

الصورة الرمزية
إهمال
المنشورات ذات الصلة الردود أدوات العرض النشاط
1
يونيو 25
375
1
يونيو 25
325
1
مايو 25
900
0
مارس 25
525
1
ديسمبر 24
3201