Angular and Latte separate Design and Data on a clean way

3 years ago

thundervoice
Member | 11
+
0
-

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

3 years ago

Pavel Janda
Member | 797
+
+1
-

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.

3 years ago

David Grudl
Nette Core | 6787
+
+3
-

or

public function actionDefault()
{
    $data = ['hello' => 'World'];

    $this->sendJson($data);
}

3 years ago

thundervoice
Member | 11
+
0
-

Thanks a lot!

It works well.