$scope.testing is being added as the button Id correctly but clicking the button doesn't fire the alert.
See example - http://plnkr.co/edit/RtidzgiUI7ZAMOTu3XHy?p=preview
CONTROLLER
var app = angular.module('StockCategory', []);
app.controller('stockCategoryController', function($scope) {
$scope.testing = 'World';
$scope.saveCategory = function() {
alert('hello');
}
});
HTML
<div class="stock-categories" ng-app="StockCategory" ng-controller="stockCategoryController">
<button class="btn save-cat" id="{{testing}}" ng-click="saveCategory();">Save</button>
</div>
The problem is that the button element in your plunker has an extra -
in your ng-click
directive. You can't see it in your plunker, try copy and pasting it in an unformatted text editor like notepad. You will see the extra -
that looks like this:
<button class="btn save-cat" id="{{testing}}" ng--click="doClick()">Save</button>
Possible cause would probably be because of copy and pasting code from an html page to another page or from a different document format to an html format.
To solve this, simply create another button element with the same content, don't copy and paste that button element above.
In my DEMO you will see two buttons with the same markup, the first one doesn't work while the other one works perfectly.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With