0

I'm doing a application to a calendar and I create a function that everytime change the values of my variable called "$scope.days", when I was using the version 1.0 didnt give error, but now the ngRepeat doesnt refresh, the new values go to the variable, but the ngRepeat dont show the new result...

$scope.loadMonth = function()
{
    $scope.titleCalendar = $scope.months[$scope.month-1].name + ' ' + $scope.year;
    getTotalFebruary($scope.year);

    var dtString = $scope.year + '/' + $scope.month + '/' + 1,
    date        = new Date(dtString),
    day         = 1,
    weekday     = date.getDay(),
    totalDays   = $scope.months[date.getMonth()].qty + date.getDay();

    $scope.days = [];

    for(var i = 0; i < totalDays; i++)
    {
        if(i < weekday)
            $scope.days.push('');
        else
            $scope.days.push(day++);
    }
};

my html:

<div class="day" ng-repeat="day in days"><p>{{ day }}</p></div>

If I put an alert after push new values, I can see the new values, but my ngRepeat doesnt refresh the results, I already try many things but didnt work. Somebody know the solution?

3
  • What is the error you are receiving in your console window?? Commented Jan 17, 2014 at 15:53
  • In HTML about the ng-repeat put {{days|json}} and see what is the output Commented Jan 17, 2014 at 15:55
  • I was seeing in firefox developer tools and doesn't give error, but by the firebug, was giving ngRepeat:dupes so I put what is recommended docs.angularjs.org/error/ngRepeat:dupes and it worked! Thanks!! Commented Jan 17, 2014 at 16:11

1 Answer 1

0

Not sure I understand what you are trying to achieve given the small sample of code you provided but if you look at this sample you'll see that it should update the display every time you click the click me text, just enter either 1,2, or 3 in the input area. you might want to check that looping logic of yours.

<html lang="en-US" ng-app="mainModule">
<head>
    <meta charset="UTF-8">
    <title></title>
    <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.4/angular.min.js"></script>

</head>
<body>
    <div ng-controller="mainController">
        <input type="text" ng-model="monthModel" placeholder="enter 1 2 or 3"/>
        <h1 ng-click="loadMonth(monthModel)">Click Me to Repeat</h1>         
        <span class="day" ng-repeat="day in days">{{ day }} , </span>
    </div>
    <script type="text/javascript">
        var app = angular.module("mainModule", []);

        app.controller("mainController", function ($scope) {
        //$scope.monthModel = 1; // default some date
        $scope.year = "2014";
        $scope.months = [
                        {"name":"January", "qty":10},
                        {"name":"February", "qty":5},
                        {"name":"March", "qty":10},                     
                        ];
        $scope.loadMonth = function(monthModel)
        {
            $scope.month = monthModel;
            $scope.titleCalendar = $scope.months[$scope.month-1].name + ' ' + $scope.year;
            //getTotalFebruary($scope.year);        

            var dtString = $scope.year + '/' + $scope.month + '/' + 1,
            date        = new Date(dtString),
            day         = 1,
            weekday     = date.getDay(),
            totalDays   = $scope.months[date.getMonth()].qty + date.getDay();

            $scope.days = [];

            for(var i = 0; i < totalDays; i++)
            {
                //if(i < weekday)
                //  $scope.days.push('');
                //else
                    $scope.days.push(day++);

                console.log($scope.days) ;
            }
        };
        });
    </script>
</body>
</html>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.