As I work on developing a single-page web application with a focus on the AngularJS framework, I've run into an issue while utilizing the ng-click directive.
It seems that upon clicking, the directive isn't functioning as expected. The associated method is not being called (and I'm unable to troubleshoot it).
Here's the code snippet in question:
template file:
<div ng-controller="BonusCtrl as bonusManager">
<!-- [...] -->
<button style="margin-top: 5px"
class="btn btn-success" ng-click="add()"><i class="fa fa-plus"/> Règle de calcul</button>
<!-- [...] -->
</div>
controller:
idServerApp.controller('BonusCtrl', ['$scope', 'webService', 'math', 'DATERANGE_OPTIONS', function ($scope, webService, math, DATERANGE_OPTIONS) {
$scope.add = function() {
console.log('foo'); // no call
var newItem = {
brandId: undefined,
days: 0,
priceMinEVAT: 0,
bonus: 0
};
$scope.rules.push(newItem);
};
Any insights on what might be causing this problem?
Edit 1
I attempted replacing bonusManager.add() with add(), and BonusCtrl.add(). I also experimented with substituting $scope with this, or removing the controllerAs.
Complete JSFiddle (utilizing some of my services)
Edit 2
Thank you for your responses. I managed to solve the issue myself, and it turned out to be a simple oversight. I forgot to include a closing div tag in the HTML template, resulting in the controller not being properly defined.