I have a view that, at it`s first load, the controller is firing every funcion twice. If I press back button and go back to the view, this behavior stops and everything goes back to normal. Is this some kind of bug?
The controller is only set once in routing.
$stateProvider
.state(‘quantidade’, {
url: ‘/quantidade/:codigoProduto/:precoProduto/:descricaoProduto’,
templateUrl: ‘templates/quantidade.html’,
controller: ‘QuantidadeController’
})
This is my index.html dependencies:
<link href="Content/ionic.css" rel="stylesheet" />
<link rel="stylesheet" href="http://code.ionicframework.com/ionicons/1.4.1/css/ionicons.min.css">
<script src="scripts/ionic.bundle.js"></script>
<script src="js/app.js"></script>
<script src="js/controllers.js"></script>
<script src="js/services.js"></script>
<link href="css/index.css" rel="stylesheet" />
<link href="css/style.css" rel="stylesheet">
<script src="cordova.js"></script>
<script src="scripts/platformOverrides.js"></script>
This is my controller, function ‘mais’ is called twice when I click the button:
.controller(‘QuantidadeController’, function ($scope, $rootScope, $state, RedeVictorServices, $stateParams, $ionicPopup) {
$scope.codigoProduto = $stateParams.codigoProduto;
$scope.descricaoProduto = $stateParams.descricaoProduto;
var str = $stateParams.precoProduto;
var num = parseFloat(str.replace(',', '.').replace(' ', ''));
$scope.valorProduto = num;
$scope.precoAcumulado = num;
$scope.quantidade = 1;
if ($rootScope.qtdCheck == 1) {
$rootScope.qtdCheck = 2;
$state.go($state.current, {}, { reload: true });
}
$scope.mais = function () {
$scope.quantidade = $scope.quantidade + 1;
$scope.precoAcumulado = num * $scope.quantidade;
}