Simple code error

I am new with coldbox, I try the following simple code, but I just a error

component{

property name="contactService" inject="ContactService";

function index( event, rc, prc ){
	prc.aContacts = contactService.getAll();
	event.setView( "contacts/index" );
}

}

the code “prc.aContacts = contactService.getAll();” has the error as "variable [CONTACTSERVICE] doesn’t exist ",but it should exist in code.

it seems WireBox has the error. Do I have to change config file to fix this? Thanks

Do you have a ContactService in your models folder?

1 Like

This code works fine.

component{

function index( event, rc, prc ){

    contactService = getInstance("ContactService");

    prc.aContacts = contactService.getAll();

    event.setView( "contacts/index" );

}

}

I do not know why previous code not working. Thanks

Can you try reiniting the site, or worse case, restart? It’s possible that ColdBox isn’t seeing the property but reiniting should take care of it.