Closed jonaskuiler closed 10 years ago
Would you be interested in creating a plugin? See here for details: https://github.com/davej/angular-classy/issues/6
I want the next version of Classy to be modular so that you can add/remove Classy features easily using plugins.
Might be as simple as this =p
on_module = angular.module 'classy-on', ['classy-core']
on_module.classy.plugin.controller
name: 'on'
options:
enabled: true
isActive: (klass, deps) ->
if @options.enabled and angular.isObject(klass.on)
if !deps.$scope
throw new Error "You need to inject `$scope` to use the watch object"
return false
return true
postInit: (klass, deps, module) ->
if !@isActive(klass, deps) then return
for key, fn of klass.on
deps.$scope.$on key, angular.bind klass, fn
return
@wuxiaoying Thanks, looks good to me (although I haven't tested it)! If you want to create a repo called 'classy-on' (or 'classy-events') and add it to bower then I will link to it on the Angular Classy site when 0.5 has been released.
Closing. Please see: https://github.com/wuxiaoying/classy-on
It would be great if you could add a method to your controllers called "events", or something like that, where you can bind your scope events (this.scope.$on('event')) and attach handlers to them.