Angular and Latte separate Design and Data on a clean way
Notice: This thread is very old.
- thundervoice
- Member | 10
Hy Guys!
For me it's not clear how i can Latte Template (only for HTML) and JSON Responses throw xhr separated? I like to separate Design and Data.
I will have a Folder structure like this:
- Models (JSON Responses)
- Contacts (in JSON Format)
- Orders (in JSON Format) et.
- Views (HTML Responses)
- Homepage
- Customers
- Contacts
- Orders etc.
The first problem is, that Tracy self include a JavaScript in all Presenters. Beacuse this situation can't Browser interprete the Data as JSON. Is it Posible to find another Way to put out only the JSON (Model) Responses? I like the JSON Data raw. It isn't possible data directly to bind with Model?
The second Problem is, how i can do a three-way-data-bindng with Angular? I haven't found any Ideas for Nette.
Any Ideas?
Greez from Switzerland
- Pavel Janda
- Member | 977
You can send a response in JSON like this:
public function actionDefault()
{
$data = ['hello' => 'World'];
$this->sendResponse(new \Nette\Application\Responses\JsonResponse($data));
}
Now there should be no Tracy JS.
- David Grudl
- Nette Core | 8228
or
public function actionDefault()
{
$data = ['hello' => 'World'];
$this->sendJson($data);
}