角度语法错误或逻辑错误?

时间:2015-09-29 14:24:19

标签: angularjs ionic-framework

我是角度和离子框架的新手。但我想尝试一个迷你日历。我不明白我做错了什么

我的calendar.js文件

angular.module('starter.Directives', []);
angular.module('starter.Directives').directive("calendar", function(){
return {
    restrict: "E",
    templateUrl: "templates/calendar.html",
    scope: { selected: "=" },
    link: function(scope) {
        scope.selected = _removeTime(scope.selected || moment());
        scope.month = scope.selected.clone();
        var start = scope.selected.clone();
        start.date(1);
        _removeTime(start.day(0));
        _buildMonth(scope, start, scope.month);

        scope.select = function(day) { scope.selected = day.date; };
        scope.next = function() {
            var next = scope.month.clone();
            _removeTime(next.month(next.month()+1).date(1));
            scope.month.month(scope.month.month()+1);
            _buildMonth(scope, next, scope.month);
        };
        scope.previous = function() {
            var previous = scope.month.clone();
            _removeTime(previous.month(previous.month()-1).date(1));
            scope.month.month(scope.month.month()-1);
            _buildMonth(scope, previous, scope.month);
        };
    }
};
function _removeTime(date){ 
    return date.hour(0).minute(0).second(0).millisecond(0);
    //return date.day(0).hour(0).minute(0).second(0).millisecond(0); }
function _buildMonth(scope, start, month) {
    scope.weeks = [];
    var done = false, date = start.clone(), monthIndex = date.month(), count = 0;
    while (!done) {
        scope.weeks.push({ days: _buildWeek(date.clone(), month) });
        date.add(1, "w");
        done = count++ > 2 && monthIndex !== date.month();
        monthIndex = date.month();
    }
}
function _buildWeek(date, month) {
    var days = [];
    for (var i = 0; i < 7; i++) {
        days.push({
            name: date.format("dd").substring(0, 1),
            number: date.date(),
            isCurrentMonth: date.month() === month.month(),
            isToday: date.isSame(new Date(), "day"),
            date: date
        });
        date = date.clone();
        date.add(1, "d");
    }
    return days;
}

});

我正在加载脚本src =&#34; calendar.js&#34;然后使用该指令,但没有任何显示。我在safari中说错误

[Error] SyntaxError: Unexpected token ')'
(anonymous function) (calendar.js, line 59)

那么我的错字在哪里,或者我不理解的是什么。我确定这很简单,但我不明白。我也是javascript的新手并没有帮助。

1 个答案:

答案 0 :(得分:2)

当你评论第32行时,你拿出了一个}:

function _removeTime(date){ 
    return date.hour(0).minute(0).second(0).millisecond(0);
  //return date.day(0).hour(0).minute(0).second(0).millisecond(0); }
} <-- this is missing

只需将}添加到_removeTime函数

末尾的第32行