dimanche 2 mai 2021

How to call a function in a component from another component n ember.js?

I am in a print-user component after I click edit button I am redirecting edit-user component. I have to send the data from print-user to edit-user. So I am calling the edit-user component-class function from print-user component-class. But it is showing the error

app/components/print-user.hbs

</input5>
    <table class="styled-table">
        <thead>
            <tr><th>User Id</th>
                <th>Firstname</th>
                <th>Lastname</th>
                <th>Mailid</th>
                <th>Delete</th>
            </tr>
        </thead>
        
            <tbody>
                <tr>
                    <td></td>
                    <td></td>
                    <td></td>
                    <td></td>
                    <LinkTo @route="edit-user" ><button  >Edit</button>r</LinkTo></td>
                </tr>
            </tbody>
        
    </table>

app/components/print-user.js

import Component from '@glimmer/component';
import {action} from "@ember/object";
import {tracked} from "@glimmer/tracking";
import EditUserComponent from './edit-user';
export default class PrintUserComponent extends Component {
    @tracked dummyresponse="";
    @action 
    async printuser (){
        let response=await fetch("/UserManagement/SearchServlet",
        {   method: "POST",
            body: JSON.stringify({
                "type": "",
                "searchtext": ""
            })
        });
        this.dummyresponse=await response.json();
        
    }
    edituser (id,firstname,lastname,mailid){
        alert("print-user.js entered");
        console.log(EditUserComponent.edituser(id,firstname,lastname,mailid));
        alert("print-user.js after method call entered");
    }
}

app/components/edit-user.hbs

import Component from '@glimmer/component';

export default class EditUserComponent extends Component {

    async edituser (id,firstname,lastname,mailid){
        alert("edit-user.js entered");
        let response=await fetch("/UserManagement/UserManagementServlet",
        {   method: "POST",
            body: JSON.stringify({
                "type": "edit",
                "id": id,
                "firstname":firstname,
                "lastname":lastname,
                "mailid":mailid
            })
        });
    }
}

app/components/edit-user.js

import Component from '@glimmer/component';

export default class EditUserComponent extends Component {

    async edituser (id,firstname,lastname,mailid){
        alert("edit-user.js entered");
        let response=await fetch("/UserManagement/UserManagementServlet",
        {   method: "POST",
            body: JSON.stringify({
                "type": "edit",
                "id": id,
                "firstname":firstname,
                "lastname":lastname,
                "mailid":mailid
            })
        });
    }
}
Uncaught TypeError: _editUser.default.edituser is not a function
    at Proxy.edituser (print-user.js:88)
    at Proxy.<anonymous> (runtime.js:7105)



Aucun commentaire:

Enregistrer un commentaire