[英]Angular $interval returns f is not a function
我试图建立一个角度的文本时钟,并且控制台返回错误“ 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();
}]);
您需要在其中放置一个回调,而不是将代码编码为string
:
$interval(function() {
showTime(elm);
}, 1000);
https://docs.angularjs.org/api/ng/service/ $ interval#usage
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.