brandenwagner
brandenwagner

Reputation: 138

Angular syntax error or logic error?

Im new to angular as well as the ionic framework. But i am trying to put in a mini calendar. i don't understand what i am doing wrong

My calendar.js file

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;
}

});

i am loading the script src="calendar.js" and then using the directive, but nothing shows up. and i am getting an error in safari saying

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

So where is my typo, or what am i not understanding. Im sure this is something simple but i don't see it. Im new to javascript too which doesn't help.

Upvotes: 0

Views: 89

Answers (1)

Lucas
Lucas

Reputation: 10303

When you commented line 32 you took out a } :

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

Just add the } to line 32 at the end of _removeTime function

Upvotes: 2

Related Questions