Finally, the problem turns out not to be that, but another conflict between
ng-if and
ng-options that I can not seem to overcome.
The function montantAnnuel() works well, but when I use
ng-if to show a group of 2 inputs, then it does not work anymore.
App.js
var SupportDemandeApp = angular.module('SupportDemandeApp', ['ngMessages']);
SupportDemandeApp.controller('SupportDemandeCtrl', ['$scope', SupportDemandeCtrl]);
function SupportDemandeCtrl($scope) {
$scope.typeContrat = function () {
$scope.types = ['Niv.I - Impartition IMS',
'Niv.II - Impartition TMA / AMS',
'Niv.III - Projet',
'Niv.IV - Impartition BPO',
'Multi - Tiers avec Impartition',
'Multi-Tiers CS & Projet',
'Vente de licence ou produit sans services ni modification'];
$scope.selectedTypeContrat = {};
};
$scope.montantAnnuel = function () {
$scope.inputMontantAnnuel = 0;
if (isNaN($scope.inputMontantAnnuel)) {
$scope.inputMontantAnnuel = 0;
}
else {
$scope.inputMontantAnnuel = ($scope.inputMontantGlobalAffaire / $scope.inputDureeAnnee);
}
};
}
Index.cshtml :
<script src="~/ScriptsJS/App.js"></script>
<div ng-app="App" ng-controller="Ctrl">
<form class="form-horizontal" id="supportDemandeForm" name="supportDemandeForm" method="post" ng-submit="validationSupportDemande(supportDemandeForm.$valid)" novalidate>
<fieldset>
<div class="form-group">
<label for="inputMontantGlobalAffaire" class="col-lg-2 control-label">Montant global prévu de l'affaire (en K€)</label>
<div class="col-lg-10">
<input type="number" class="form-control" id="inputMontantGlobalAffaire" name="inputMontantGlobalAffaire" ng-model="inputMontantGlobalAffaire" ng-change="montantAnnuel()" pattern="[0-9]+(\\.[0-9][0-9]?)?" required>
</div>
</div>
<div class="form-group">
<label for="selectTypeContrat" class="col-lg-2 control-label">Type de contrat (IS/OS)<span style="color:red"> *</span></label>
<div class="col-lg-10">
<select class="form-control" id="selectTypeContrat" name="selectTypeContrat" ng-model="selectedTypeContrat.type" ng-init="typeContrat()" ng-options="type for type in types" required></select>
</div>
</div>
<div class="form-group check-element" ng-if="selectedTypeContrat.type == 'Niv.I - Impartition IMS' || selectedTypeContrat.type == 'Niv.II - Impartition TMA / AMS' || selectedTypeContrat.type == 'Niv.IV - Impartition BPO' || selectedTypeContrat.type == 'Multi-Tiers avec Impartition'">
<div>
<label for="inputDureeAnnee" class="col-lg-2 control-label">Durée (en années)</label>
<div class="col-lg-10">
<input type="number" class="form-control" id="inputDureeAnnee" name="inputDureeAnnee" ng-model="inputDureeAnnee" ng-change="montantAnnuel()" required>
</div>
</div>
<div>
<label for="inputMontantAnnuel" class="col-lg-2 control-label">Montant annuel (en K€)</label>
<div class="col-lg-10">
<input readonly type="number" class="form-control" id="inputMontantAnnuel" name="inputMontantAnnuel" ng-model="inputMontantAnnuel" />
</div>
</div>
</div>
</fieldset>
</form>
</div>