Skip to content

Instantly share code, notes, and snippets.

@wookets
Last active December 12, 2015 04:58
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wookets/4718161 to your computer and use it in GitHub Desktop.
Save wookets/4718161 to your computer and use it in GitHub Desktop.
AngularJS Mixins - By passing a scope to a mixin you can keep your controllers simple and reuse mixin code through out your app.
window.AppCtrl = ($scope, $route, $timeout) ->
# mixins
mixin_generic($scope) # setup $scope.generic()
# now we can...
$scope.generic()
# a safer version of $scope.$apply()... It will tame exceptions if $apply() or $digest() is already called.
window.mixin_generic = ($scope) ->
$scope.generic = () ->
console.log 'inside mixin'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment