Elasticsearch和AngularJS(Elasticsearch and AngularJS)

编程入门 行业动态 更新时间:2024-10-26 17:21:05
Elasticsearch和AngularJS(Elasticsearch and AngularJS)

尝试通过制作一个简单的搜索应用程序来学习Elasticsearch和AngularJS。

我知道Angular的最佳实践是模块化所有代码,但......

我经历了一个教程,并有一些示例代码,它看起来不错,它只是没有分解成模块,它看起来像这样:

var searchApp = angular.module('searchApp', ['elasticsearch', 'ngSanitize', 'ui.bootstrap']); searchApp.controller('typeahead', ['ui.bootstrap', function(ui.bootstrap){ //add $http get }]);//added searchApp.controller('SearchResultsList', ['$scope', 'searchService', 'filterService', '$sce', function($scope, searchService, filterService, $sce) {

之后又有很多代码。

是否值得尝试将其分解为模块(控制器,服务,过滤器和配置和路由的app.js?

任何建议,建议都非常感谢。

Trying to learn Elasticsearch and AngularJS by making a simple search app.

I know best practice with Angular is to modularize all the code but...

I went through a tutorial and have some sample code and it looks good, its just not broken down into modules, it looks like this:

var searchApp = angular.module('searchApp', ['elasticsearch', 'ngSanitize', 'ui.bootstrap']); searchApp.controller('typeahead', ['ui.bootstrap', function(ui.bootstrap){ //add $http get }]);//added searchApp.controller('SearchResultsList', ['$scope', 'searchService', 'filterService', '$sce', function($scope, searchService, filterService, $sce) {

and a whole lot of code after that.

Is it worth it to try and break it down into modules (controllers, services, filters and app.js with config and routes?

Any advice, recommendations are highly appreciated.

最满意答案

根据AngularJs的最佳实践和文档,控制器不应该有您的业务逻辑。 我认为模块化您的应用程序更好。

如你所知:

使用控制器:

设置$ scope对象的初始状态。 向$ scope对象添加行为。

不要使用控制器:

操纵DOM - 控制器应仅包含业务逻辑。 将任何表示逻辑放入控制器会显着影响其可测试性。 Angular对大多数情况和指令进行数据绑定以封装手动DOM操作。 格式输入 - 改为使用角度形式控件。 滤镜输出 - 改为使用角度滤镜。 跨控制器共享代码或状态 - 改为使用角度服务。 管理其他组件的生命周期

According to the AngularJs best practices and documentation, controllers should not have your business logic. I think its better to modularized your application.

As u know:

Use controllers to:

Set up the initial state of the $scope object. Add behavior to the $scope object.

Do not use controllers to:

Manipulate DOM — Controllers should contain only business logic. Putting any presentation logic into Controllers significantly affects its testability. Angular has databinding for most cases and directives to encapsulate manual DOM manipulation. Format input — Use angular form controls instead. Filter output — Use angular filters instead. Share code or state across controllers — Use angular services instead. Manage the life-cycle of other component

更多推荐

本文发布于:2023-07-14 23:38:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1108336.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:Elasticsearch   AngularJS

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!