Skip to content

Commit

Permalink
dynamic templating
Browse files Browse the repository at this point in the history
  • Loading branch information
siddii committed May 23, 2013
1 parent 92d92c3 commit a7c540a
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 17 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# angular-timer — Sample AngularJS directive demonstrating re-usability & interoperability

This project is a sample AngularJS directive demonstrating
Sample AngularJS directive


21 changes: 5 additions & 16 deletions app/js/timer.js
Original file line number Diff line number Diff line change
@@ -1,26 +1,15 @@
angular.module('timer', [])
.directive('timer', function ($timeout) {
.directive('timer', function ($timeout, $compile) {
return {
restrict: 'E',
// template: "<h3>{{timeTaken}}</h3>",
replace: false,
scope: {interval: '=interval'},
link: function ($scope, $element) {


console.log('###### $element = ', $element);

console.log('###### BEFORE $element.html() = ', $element.html());

// $element[0].innerHTML = '<h3>{{timeTaken}}</h3>';

if ($element.html() === '') {
console.log('###### setting default template', $element);
$element.html('<h3>{{timeTaken}}</h3>');
controller: function ($scope, $element) {
if ($element.html().trim().length === 0) {
var template = $compile('<h3>{{timeTaken}}</h3>')($scope);
$element.parent().append(template);
}

console.log('###### AFTER $element.html() = ', $element.html());

$scope.startTime = null;
$scope.timeoutId = null;

Expand Down

0 comments on commit a7c540a

Please sign in to comment.