2016-11-18 10:27

如何重构前端JS到Angular 2与PHP MVC后端很好地配合? [关闭]

  • php
  • angularjs
  • javascript
  • jquery

I have a huge PHP MVC web application, which now uses for some click events and modal dialog rendering jQuery. To stay confident with modern frontend technologies, I would like to refactor the JavaScript code to run under Angular 2. But my main question is: How can I do this? Angular 2 doesn't have controllers anymore, which really complicate things in my use case. I mainly just need some click event subscribing and modal dialog handling on the JavaScript side. The most part of the HTML is rendered in the PHP backend.

For example, let's say we have a news site (route: index/news) with many news entries. Actually, this is completely done in the backend by fetching data from the database, load a helper for each news entry and output it in the view. If I would refactor this to a component, then I would have massively ajax requests for each news entry. I believe this is not the preferred way of using Angular 2. Also, what I really need is some interaction on buttons etc.. I think it is also not the meaning of Angular 2 to create a small template string with the buttons and an ngClick inside of that, just for having an ngClick on my button.

So, please tell me how I can integrate Angular 2 in a nice way, so that these two technologies play well with each other.

  • 点赞
  • 回答
  • 收藏
  • 复制链接分享