$scope.dates = new Date();
var ed = new Date($filter('date')($scope.dates,'hh:mm:ss'));
在第二行中,我想获取时间,但出现引用错误。
我的问题是什么?
(function(){
var app = angular.module('notesApp',['angular-markdown-editable']);
app.controller('notesController', function($scope, $interval){
function updateTime() {
$scope.dates = new Date();
var ed = new Date($filter('date')($scope.dates,'hh:mm:ss'));
alert(ed);
}
...
最佳答案
您需要在您的 Controller 声明中注入(inject)$filter
,例如:
app.controller('notesController', function($scope, $interval, $filter){ // <-- filter was added at the end
我知道这个问题与 Angular 有关,但我建议您考虑使用 JavaScript 日期函数,例如:
var date = new Date();
var seconds = date.getSeconds();
var minutes = date.getMinutes();
var hour = date.getHours();
关于javascript - 使用 angularjs 过滤日期时出现引用错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31329082/