我在我的项目中使用angular + momentjs。我还添加了angular-moment库。 这是我的fiddle
在控制器方法中使用moment给出了错误:
TypeError: undefined is not a function
at new <anonymous> (http://fiddle.jshell.net/alkimake/LsNtN/1/show/:56:23)
at invoke (http://cdnjs.cloudflare.com/ajax/libs/angular.js/1.2.1/angular.js:3624:28)
at Object.instantiate (http://cdnjs.cloudflare.com/ajax/libs/angular.js/1.2.1/angular.js:3636:23)
at http://cdnjs.cloudflare.com/ajax/libs/angular.js/1.2.1/angular.js:6639:28
at http://cdnjs.cloudflare.com/ajax/libs/angular.js/1.2.1/angular.js:6083:34
at forEach (http://cdnjs.cloudflare.com/ajax/libs/angular.js/1.2.1/angular.js:307:20)
at nodeLinkFn (http://cdnjs.cloudflare.com/ajax/libs/angular.js/1.2.1/angular.js:6070:11)
at compositeLinkFn (http://cdnjs.cloudflare.com/ajax/libs/angular.js/1.2.1/angular.js:5536:15)
at publicLinkFn (http://cdnjs.cloudflare.com/ajax/libs/angular.js/1.2.1/angular.js:5444:30)
at http://cdnjs.cloudflare.com/ajax/libs/angular.js/1.2.1/angular.js:1287:27
我想知道为什么我不能在控制器方法或范围内使用时刻。
答案 0 :(得分:0)
您使用错误的方法访问日,月和日年价值。应该是:
var sd = $scope.s.date();
var md = $scope.s.month();
var yd = $scope.s.year();
请参阅moment docs