需要帮助构建Angular应用程序

时间:2022-08-25 02:09:14

I have a basic angular app, users can post Adverts, now I am working on how to search / filter for adverts. I am currently using a filter like so..

我有一个基本的角度应用程序,用户可以发布广告,现在我正在研究如何搜索/过滤广告。我目前正在使用这样的过滤器..

<a data-ng-repeat="advert in filtered = (adverts | filter:filterBySearch) | startFrom:(currentPage-1)*entryLimit | limitTo:entryLimit" data-ng-href="#!/adverts/{{advert._id}}" class="list-group-item">

where I have created my own fiter, filterBySearch

我在哪里创建了自己的fiter,filterBySearch

I also have a range slider for filtering by a range of prices, and I have all this working with pagination.

我还有一个范围滑块,可以按一系列价格进行过滤,而且所有这些都与分页有关。

My concern is because I have declared <section data-ng-controller="AdvertsController"> at the top of the homepage in order to use the AdvertsController for Advert logic, I am now finding I am putting logic in here around, pagination, the range slider, filtering logic etc. I would like to know how best to split this logic out into their own controllers or whatever it needs.

我担心的是因为我在主页的顶部声明了

以便使用AdvertsController for Advert逻辑,我现在发现我在这里放置逻辑,分页,范围滑块,过滤逻辑等。我想知道如何最好地将这个逻辑分解到他们自己的控制器或它需要的任何东西。

2 个解决方案

#1


1  

The controller should not he hadling such complex business logics in itself. It must be used for binding scope elements, handling events, updating states etc. I would suggest pulling your pagination, range slider, filtering logics etc in dedicated angular service and inject the it into your AdvertsController. This way you can also utilize them in any other view/controller you require.

控制器本身不应该使用如此复杂的业务逻辑。它必须用于绑定范围元素,处理事件,更新状态等。我建议在专用角度服务中提取您的分页,范围滑块,过滤逻辑等,并将其注入您的AdvertsController。这样,您还可以在您需要的任何其他视图/控制器中使用它们。

Read more about modularity in AngularJS here

在此处阅读有关AngularJS模块化的更多信息

#2


0  

If you have business logic pertaining to elements inside of your tag, then it still makes sense to have all of your code inside of that controller. It might make more sense to rename your Controller to something that better suits your needs.

如果您有与标记内部元素相关的业务逻辑,那么将所有代码都放在该控制器中仍然是有意义的。将Controller重命名为更适合您需求的内容可能更有意义。

#1


1  

The controller should not he hadling such complex business logics in itself. It must be used for binding scope elements, handling events, updating states etc. I would suggest pulling your pagination, range slider, filtering logics etc in dedicated angular service and inject the it into your AdvertsController. This way you can also utilize them in any other view/controller you require.

控制器本身不应该使用如此复杂的业务逻辑。它必须用于绑定范围元素,处理事件,更新状态等。我建议在专用角度服务中提取您的分页,范围滑块,过滤逻辑等,并将其注入您的AdvertsController。这样,您还可以在您需要的任何其他视图/控制器中使用它们。

Read more about modularity in AngularJS here

在此处阅读有关AngularJS模块化的更多信息

#2


0  

If you have business logic pertaining to elements inside of your tag, then it still makes sense to have all of your code inside of that controller. It might make more sense to rename your Controller to something that better suits your needs.

如果您有与标记内部元素相关的业务逻辑,那么将所有代码都放在该控制器中仍然是有意义的。将Controller重命名为更适合您需求的内容可能更有意义。