The following would work without needing to inject a controller, you simply add a close method to the alert you are building:
.factory('AppAlert', ['$rootScope', ($rootScope) -> $rootScope.alerts = [] alertService = add: (type, msg) -> $rootScope.alerts.push { type: type, msg: msg, close: -> alertService.closeAlert(this) } closeAlert: (alert) -> @closeAlertIdx $rootScope.alerts.indexOf(alert) closeAlertIdx: (index) -> $rootScope.alerts.splice index, 1 ])
and in the alert directive simply replace the close to close="alert.close()"
close="alert.close()"
The following would work without needing to inject a controller, you simply add a close method to the alert you are building:
and in the alert directive simply replace the close to
close="alert.close()"