You are very close. As Jaromanda X suggested, just start from 1 and keep going until the month changes (and don't forget to keep variables local). You'll need to copy the date each time:
function Ctrl($scope) {
$scope.dates = [];
var d = new Date(),
i = 1,
m = d.getMonth();
// Set date to start of month
d.setDate(i);
// Store the current month and keep going until it changes
while (d.getMonth() == m) {
// Store dates as a string (format however you wish)
$scope.dates.push('' + d);
// Or store dates as Date objects
$scope.dates.push(new Date(+d));
// Increment date
d.setDate(++i);
}
// return something?
}
Edit
Allow entry of month (also example of do rather than for loop):
// Use calendar month number for month, i.e. 1=jan, 2=feb, etc.
function Ctrl($scope, month) {
$scope.dates = [];
var d = new Date();
d.setMonth(month - 1, 1);
do {
$scope.dates.push('' + d);
d.setDate(d.getDate() + 1);
} while (d.getDate() != 1)
}
Or allow entry of month and year with defaults of current month and year:
function Ctrl($scope, month, year) {
$scope.dates = [];
var d = new Date();
d.setFullYear(+year || d.getFullYear(), month - 1 || d.getMonth(), 1);
do {
$scope.dates.push('' + d);
d.setDate(d.getDate() + 1);
} while (d.getDate() != 1)
}