JavaScript angularjs 里 controller 的重复代码怎么办

guyanbiao · June 13, 2013 · Last by ichord replied at June 14, 2013 · 6871 hits

有几个 controller 都要执行同样一段代码,现在是分别都写在了 controller 里面,有什么方法提取出来么,怎么做到 DRY?

跟 Rails 一样,做 Helper

#1 楼 @winnie 做 helper 还是每次都要在 controller 引用啊,我的意思是类似 before_filter 这样的,指定某几个或者全部 controller 在执行的时候都要先做某一件事

目前能想到的就是继承的方法,比较土

#3 楼 @winnie 那就跟 rails 的 controller 继承 ApplicationController 一样了

You need to Sign in before reply, if you don't have an account, please Sign up first.