angular-timer
angular-timer copied to clipboard
[resovled]Not working,can't add dynamic callback from $http response
https://guides.github.com/features/mastering-markdown/I tried every guide here nothing worked: Not this(set ng-if): ibids.controller("countDown",function($http,$scope,$timeout){ $scope.timerRunning = true;
var id = $('#hiddenid').val();
var req = {
method: 'POST',
url: 'process.php?action=timer&prodid='+id,
headers: {
'Content-Type': 'json'
},
data: 'action=timer'
}
$http(req).then(function(req){
console.log(req.data['datetime']);
$scope.timerOn = true;
if($scope.timerOn == true){
$scope.countdowntimer = req.data['datetime'];
}
}, function(){
});
});
Not this(timeout) not append nothing i have this div id:
ibids.controller("countDown",['$http', '$scope', '$timeout', '$compile', '$element',function($http,$scope,$timeout,$compile,$element){
var getTimer = function () {
var id = $('#hiddenid').val();
var req = {
method: 'POST',
url: 'process.php?action=timer&prodid='+id,
headers: {
'Content-Type': 'json'
},
data: 'action=timer'
}
$http(req).then(function(req){
$timeout(function (){
var endTime = req.data['datetime'];
var timerScope = $scope.$new();
var timerNode = $('<timer language="he" countdown="' + endTime +'" interval="1000">{{days}} ימים, {{hours}} שעות,{{mminutes}} דקות,{{sseconds}} שניות</timer>');
$element.find('#countdown').append(timerNode);
$compile(timerNode)(timerScope);
});
}, function(){
});
};
//We need this timeout to truly simulate asynchronous/REST API call
$timeout(function (){
getTimer();
}, 2000);
}]);
FINALLY WORKING THIS IS THE CODE IF ANYONE WILL STUCK OUT 2 DAYS HERE IS WORKING EXAMPLE TO USE $HTTP and TIMER:
ibids.controller("countDown",['$http', '$scope', '$timeout', '$compile', '$element',function($http,$scope,$timeout,$compile,$element){
var getTimer = function () {
var id = $('#hiddenid').val();
var req = {
method: 'POST',
url: 'process.php?action=timer&prodid='+id,
headers: {
'Content-Type': 'json'
},
data: 'action=timer'
}
$http(req).then(function(req){
$timeout(function (){
var endTime = req.data['datetime'];
var timerScope = $scope.$new();
var timerNode = $('<timer language="he" countdown="' + endTime +'" interval="1000">{{days}} ימים, {{hours}} שעות,{{mminutes}} דקות,{{sseconds}} שניות</timer>');
$element.find('#countdowntimer').append(timerNode);
$compile(timerNode)(timerScope);
});
}, function(){
});
};
//We need this timeout to truly simulate asynchronous/REST API call
$timeout(function (){
getTimer();
}, 2000);
}]);
Good luck,nice timer thanks.