-
-
Save dfrankland/6bfe7ecf948139b30b1573d7a9e763f2 to your computer and use it in GitHub Desktop.
JS Bin // source http://jsbin.com/woqowetuze
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
<!doctype html> | |
<html ng-app="myApp"> | |
<head> | |
<title>JS Bin</title> | |
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js"></script> | |
</head> | |
<body ng-controller="myCtrl"> | |
<spinner load="loading"> | |
<blah yo="otherScopeVariable" ></blah> | |
</spinner> | |
<script id="jsbin-javascript"> | |
var app = angular.module('myApp', []); | |
app.controller('myCtrl', function($scope) { | |
$scope.otherScopeVariable = 'Blah'; | |
$scope.loading = true; | |
setTimeout( | |
function () { | |
$scope.$applyAsync( | |
function () { | |
$scope.loading = false; | |
} | |
); | |
}, 1000 | |
); | |
}); | |
app.directive('blah', function () { | |
return { | |
restrict: 'E', | |
template: '<span><i>Really {{otherScopeVariable}}</i></span>' | |
} | |
}); | |
app.directive('spinner', function () { | |
return { | |
restrict: "E", | |
replace: true, | |
transclude: true, | |
scope: { load: '=' }, | |
template: '<strong>Loading...</strong>', | |
link: function(scope, element, attrs, ctrl, transclude){ | |
var cancelWatch = scope.$watch('load', function (stillLoading) { | |
if (!stillLoading) { | |
element.replaceWith(transclude()); | |
cancelWatch(); | |
} | |
}); | |
}, | |
}; | |
}); | |
</script> | |
<script id="jsbin-source-javascript" type="text/javascript">var app = angular.module('myApp', []); | |
app.controller('myCtrl', function($scope) { | |
$scope.otherScopeVariable = 'Blah'; | |
$scope.loading = true; | |
setTimeout( | |
function () { | |
$scope.$applyAsync( | |
function () { | |
$scope.loading = false; | |
} | |
); | |
}, 1000 | |
); | |
}); | |
app.directive('blah', function () { | |
return { | |
restrict: 'E', | |
template: '<span><i>Really {{otherScopeVariable}}</i></span>' | |
} | |
}); | |
app.directive('spinner', function () { | |
return { | |
restrict: "E", | |
replace: true, | |
transclude: true, | |
scope: { load: '=' }, | |
template: '<strong>Loading...</strong>', | |
link: function(scope, element, attrs, ctrl, transclude){ | |
var cancelWatch = scope.$watch('load', function (stillLoading) { | |
if (!stillLoading) { | |
element.replaceWith(transclude()); | |
cancelWatch(); | |
} | |
}); | |
}, | |
}; | |
});</script></body> | |
</html> |
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
var app = angular.module('myApp', []); | |
app.controller('myCtrl', function($scope) { | |
$scope.otherScopeVariable = 'Blah'; | |
$scope.loading = true; | |
setTimeout( | |
function () { | |
$scope.$applyAsync( | |
function () { | |
$scope.loading = false; | |
} | |
); | |
}, 1000 | |
); | |
}); | |
app.directive('blah', function () { | |
return { | |
restrict: 'E', | |
template: '<span><i>Really {{otherScopeVariable}}</i></span>' | |
} | |
}); | |
app.directive('spinner', function () { | |
return { | |
restrict: "E", | |
replace: true, | |
transclude: true, | |
scope: { load: '=' }, | |
template: '<strong>Loading...</strong>', | |
link: function(scope, element, attrs, ctrl, transclude){ | |
var cancelWatch = scope.$watch('load', function (stillLoading) { | |
if (!stillLoading) { | |
element.replaceWith(transclude()); | |
cancelWatch(); | |
} | |
}); | |
}, | |
}; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment