Hello everyone,
I have a little question. I’m updating a scope variable inside a view, but the if statements in my controller aren’t responding as desired. I inserted some relevant code in this topic. I already read some things about apply and watch, but I can’t figure it out. Thanks in advance!
Controller.js:
$scope.currentPeriod = "monthly";
// Weekly
if ($scope.currentPeriod == "weekly") {
// some code
$scope.nextWeek = function () {
// some code
};
$scope.previousWeek = function () {
// some code
}
};
// Monthly
if ($scope.currentPeriod == "monthly") {
// some code
$scope.nextWeek = function () {
// some code
};
$scope.previousWeek = function () {
// some code
}
};
dashboard.html
<a ng-click="currentPeriod = 'weekly'" class="button button-block button-balanced" id="feedback-button">Weekly</a>
<a ng-click="currentPeriod = 'monthly'" class="button button-block button-balanced" id="feedback-button">Monthly</a>
<a ng-click="info()" class="button button-block button-balanced" id="feedback-button">Ever</a>
...
<div id="datepicker" ng-if="currentPeriod == 'weekly'">
<img src="img/circle_left.png" id="dashboard-arrow" ng-click="previousWeek()">
<h4 id="date">{{startWeek | date:'dd/MM/yy'}} - {{endWeek | date:'dd/MM/yy'}}</h4>
<img src="img/circle_right.png" id="dashboard-arrow" ng-click="nextWeek()">
</div>
<div id="datepicker" ng-if="currentPeriod == 'monthly'">
<img src="img/circle_left.png" id="dashboard-arrow" ng-click="previousMonth()">
<h4 id="date">{{startMonth | date:'MMMM yyyy'}}</h4>
<img src="img/circle_right.png" id="dashboard-arrow" ng-click="nextMonth()">
</div>
Screenshot of the page: