由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
Programming版 - Angular放弃service直接用controller如何
相关主题
有人用angular 2吗? ionic 2的alpha出来了讨论node/angular route的error handling
Angular 2像Python 3一样流行不动的可能性多大?How many people use design patterns when coding?
主页上有20个js文件,怎么回事?Proxy, Decorator, Adapter, and Bridge
MVCS其实板上还有几个臭皮匠的
AngularJS 2.0有点作妖儿啊探讨一下API Gateway和Proxy的关系
除了model view controller (mvc)这种pattern还有什么pattern流行?Call assembly in c++ under linux
angular rest是应该用$http还是$resource?有什么工具可以检查内存泄漏么
Angular 1.x: How 1 controller load different partial view ?Excel Control得问题
相关话题的讨论汇总
话题: controller话题: angular话题: service话题: layer话题: backend
进入Programming版参与讨论
1 (共1页)
h******b
发帖数: 6055
1
我看过很多书/文章知道angular的controller应该是slim的,甚至不应该有business
logic。
但个人感觉来说,我用controller直接http.get, 直接在controller里用underscore.
js来sort/group/filter我的$scope数据, 感觉写起来流畅很多。大大降低了angular的
learning curve。 我始终不明白同样一个getusers(), 放controller里我只需要写一
遍,放service里我还得在controller里reference,何必呢?
如果好几个controller分享一个service我可以理解。 但最少个人小项目里,基本上
是一个界面一个api。
a9
发帖数: 21638
2
怎么方便怎么来

【在 h******b 的大作中提到】
: 我看过很多书/文章知道angular的controller应该是slim的,甚至不应该有business
: logic。
: 但个人感觉来说,我用controller直接http.get, 直接在controller里用underscore.
: js来sort/group/filter我的$scope数据, 感觉写起来流畅很多。大大降低了angular的
: learning curve。 我始终不明白同样一个getusers(), 放controller里我只需要写一
: 遍,放service里我还得在controller里reference,何必呢?
: 如果好几个controller分享一个service我可以理解。 但最少个人小项目里,基本上
: 是一个界面一个api。

l**********n
发帖数: 8443
3
it seems that you haven't written large angular projects

【在 h******b 的大作中提到】
: 我看过很多书/文章知道angular的controller应该是slim的,甚至不应该有business
: logic。
: 但个人感觉来说,我用controller直接http.get, 直接在controller里用underscore.
: js来sort/group/filter我的$scope数据, 感觉写起来流畅很多。大大降低了angular的
: learning curve。 我始终不明白同样一个getusers(), 放controller里我只需要写一
: 遍,放service里我还得在controller里reference,何必呢?
: 如果好几个controller分享一个service我可以理解。 但最少个人小项目里,基本上
: 是一个界面一个api。

g*****g
发帖数: 34805
4
书都是按照可扩展可维护的角度来写的。典型的三层架构里,controller在front tier
,你把商业逻辑写进去,不好重用。你个人写完就扔的项目当然可以怎么快怎么来。

【在 h******b 的大作中提到】
: 我看过很多书/文章知道angular的controller应该是slim的,甚至不应该有business
: logic。
: 但个人感觉来说,我用controller直接http.get, 直接在controller里用underscore.
: js来sort/group/filter我的$scope数据, 感觉写起来流畅很多。大大降低了angular的
: learning curve。 我始终不明白同样一个getusers(), 放controller里我只需要写一
: 遍,放service里我还得在controller里reference,何必呢?
: 如果好几个controller分享一个service我可以理解。 但最少个人小项目里,基本上
: 是一个界面一个api。

p*****2
发帖数: 21240
5
大实话

tier

【在 g*****g 的大作中提到】
: 书都是按照可扩展可维护的角度来写的。典型的三层架构里,controller在front tier
: ,你把商业逻辑写进去,不好重用。你个人写完就扔的项目当然可以怎么快怎么来。

h******b
发帖数: 6055
6
个人文科生土鳖思维上来说,model如果是rest还有数据库本身都比较容易理解。
比如我call个/api/users,拿到一串json,用controller倒腾一下就直接上界面了。作
为前台我一直以为/api/users就是model/service。
angular一直让我绕不过弯来的就是call这个/api/users,教科书上是应该在service/
factory里call的。
那么最大优势就是不同controller可以共享一个service/factory了。 可是我本来就
可以从不同controller来call/api/users。如果我需要共享一个getuserbyid,我会直
接在rest里面提供。 何必搞angular service呢?

tier

【在 g*****g 的大作中提到】
: 书都是按照可扩展可维护的角度来写的。典型的三层架构里,controller在front tier
: ,你把商业逻辑写进去,不好重用。你个人写完就扔的项目当然可以怎么快怎么来。

h******b
发帖数: 6055
7
的确没有,文科生半路出家。 主要是希望能有写MVP,prototype的能力。

【在 l**********n 的大作中提到】
: it seems that you haven't written large angular projects
g*****g
发帖数: 34805
8
The service/factory you talk about is not service layer in 3 tier sense. It'
s an aggregation/adaptor layer. Backend services are typically more fine-
grained and you want a more coarse-grained facade then you can do it here.
Say if you have backend services, one to store a user account, one to send
an email. You can assemble these two in this layer and call from various
controllers.

【在 h******b 的大作中提到】
: 个人文科生土鳖思维上来说,model如果是rest还有数据库本身都比较容易理解。
: 比如我call个/api/users,拿到一串json,用controller倒腾一下就直接上界面了。作
: 为前台我一直以为/api/users就是model/service。
: angular一直让我绕不过弯来的就是call这个/api/users,教科书上是应该在service/
: factory里call的。
: 那么最大优势就是不同controller可以共享一个service/factory了。 可是我本来就
: 可以从不同controller来call/api/users。如果我需要共享一个getuserbyid,我会直
: 接在rest里面提供。 何必搞angular service呢?
:
: tier

s***o
发帖数: 2191
9
If I want to have a "transaction" on this aggregation layer, what would be a
good way to implement it?

It'

【在 g*****g 的大作中提到】
: The service/factory you talk about is not service layer in 3 tier sense. It'
: s an aggregation/adaptor layer. Backend services are typically more fine-
: grained and you want a more coarse-grained facade then you can do it here.
: Say if you have backend services, one to store a user account, one to send
: an email. You can assemble these two in this layer and call from various
: controllers.

c*********e
发帖数: 16335
10
service是singleton.这个很重要,意味着你在整个project里只有一个。

【在 h******b 的大作中提到】
: 个人文科生土鳖思维上来说,model如果是rest还有数据库本身都比较容易理解。
: 比如我call个/api/users,拿到一串json,用controller倒腾一下就直接上界面了。作
: 为前台我一直以为/api/users就是model/service。
: angular一直让我绕不过弯来的就是call这个/api/users,教科书上是应该在service/
: factory里call的。
: 那么最大优势就是不同controller可以共享一个service/factory了。 可是我本来就
: 可以从不同controller来call/api/users。如果我需要共享一个getuserbyid,我会直
: 接在rest里面提供。 何必搞angular service呢?
:
: tier

x**n
发帖数: 461
11
This is typically because you don't have sufficient experiences to realize
the benefit of single responsibility.
g*****g
发帖数: 34805
12
Try to keep it in one backend service, that's most reliable. When not
possible, don't use distributed transaction, use monitoring and alert.

a

【在 s***o 的大作中提到】
: If I want to have a "transaction" on this aggregation layer, what would be a
: good way to implement it?
:
: It'

1 (共1页)
进入Programming版参与讨论
相关主题
Excel Control得问题AngularJS 2.0有点作妖儿啊
你们认为OO思想十几年后会被淘汰么?除了model view controller (mvc)这种pattern还有什么pattern流行?
Can someone help me a quick regex?angular rest是应该用$http还是$resource?
大家programming时怎么命名?Angular 1.x: How 1 controller load different partial view ?
有人用angular 2吗? ionic 2的alpha出来了讨论node/angular route的error handling
Angular 2像Python 3一样流行不动的可能性多大?How many people use design patterns when coding?
主页上有20个js文件,怎么回事?Proxy, Decorator, Adapter, and Bridge
MVCS其实板上还有几个臭皮匠的
相关话题的讨论汇总
话题: controller话题: angular话题: service话题: layer话题: backend