Created
November 30, 2014 10:36
-
-
Save AndreaPaciolla/0167d0d674d9a6eab90b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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