2017-11-01 11 views
0

私は文字の時計を角で構築しようとしていますが、コンソールはエラー "fは関数ではありません"を返しています。私は行方不明のものがありますか?

"use strict"; 
app.controller("dashboardController", ["$scope", "$location", "$interval", function ($scope, $location, $interval) { 
    var dashboard = this; 

    // Live Date and Time 
    dashboard.currentTime = function() { 
     var showMilitaryTime = false; 
     var now = new Date; 

     function showHours(theHour) 
     { 
      if (showMilitaryTime || (theHour > 0 && theHour < 13)) 
       return (theHour); 
      else if (theHour == 0) 
       return 12; 
      else return (theHour - 12) 
     } 

     function fillZeros(inValue) 
     { 
      if (inValue > 9) 
       return ":" + inValue; 
      else return ":0" + inValue; 
     } 

     function showAmPm() 
     { 
      if (showMilitaryTime) 
       return (""); 
      if (now.getHours() < 12) 
       return (" AM"); 
      else return (" PM"); 
     } 

     function showTime(elm) 
     { 
      var theTime = showHours(now.getHours()) + fillZeros(now.getMinutes()) + fillZeros(now.getSeconds()) + showAmPm(); 
      document.getElementById(elm).innerHTML = theTime; 
      $interval("showTime('"+elm+"')", 1000); 
     } 

     showTime('clock'); 
    } 

    // Initialise functions in the dashboard 
    dashboard.init = function() { 
     dashboard.currentTime(); 
    }; 

    dashboard.init(); 
}]); 

答えて

1

あなたはstringとしてそこにコールバックではなく、コードを配置する必要があります。

$interval(function() { 
    showTime(elm); 
}, 1000); 

https://docs.angularjs.org/api/ng/service/ $インターバル#使用量を

関連する問題