Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Angularjs - ng-click not firing

$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>
like image 949
garethb Avatar asked Aug 06 '14 04:08

garethb


1 Answers

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.

like image 62
ryeballar Avatar answered Oct 16 '22 11:10

ryeballar