Skip to content

Instantly share code, notes, and snippets.

@AndreaPaciolla
Created November 30, 2014 10:36
Show Gist options
  • Save AndreaPaciolla/0167d0d674d9a6eab90b to your computer and use it in GitHub Desktop.
Save AndreaPaciolla/0167d0d674d9a6eab90b to your computer and use it in GitHub Desktop.
whenReady = angular.module('whenReady', [])
# WHEN READY ALLOWS YOU TO FIRE AN EVENT FROM THE VIEW WHEN SOME DATA IS READY
# IT USES WATCHERS TO ACCOMPLISH THIS, THEN THE WATCHER IS DESTROYED
# ELEMENT USAGE: <whenready watch="user.id" do="callme()"> </whenready> # BE SURE U ADD COMPATIBILITY FOR IE
# ATTRIBUTE USAGE: <div whenready="user.id" whenready-do="callme()"> </div>
whenReady.directive('whenready', ->
restrict: "E"
link: (scope, elm, attrs) ->
watcher = scope.$watch(attrs.watch, (current_elm)->
if current_elm?
scope.$eval attrs.do
watcher()
)
)
whenReady.directive('whenready', ->
restrict: "A"
link: (scope, elm, attrs) ->
watcher = scope.$watch(attrs.whenready, (current_elm)->
if current_elm?
scope.$eval(attrs.whenreadyDo)
watcher()
)
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment