user1592129
user1592129

Reputation: 493

displaying days of week in view

I am display days of week in my template, which I am declaring in my controller like

$scope.weekday = new Array(7);
        $scope.weekday[0]="Sunday";
        $scope.weekday[1]="Monday";
        $scope.weekday[2]="Tuesday";
        $scope.weekday[3]="Wednesday";
        $scope.weekday[4]="Thursday";
        $scope.weekday[5]="Friday";
        $scope.weekday[6]="Saturday";

As i am new to angular, would like to ask if it is OK or I can optimize it.

Upvotes: 0

Views: 989

Answers (2)

Stefan Pintilie
Stefan Pintilie

Reputation: 705

Check this out, using $local object:

$locale.DATETIME_FORMATS.DAY

Upvotes: 0

Jayram
Jayram

Reputation: 19588

You can write it better like this.

$scope.weekday = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"];

Upvotes: 2

Related Questions