$scope.testing正在添加为按钮Id正确,但点击按钮不触发警报.
参见示例 – 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>
解决方法
问题在于,您的广告联盟中的按钮元素有一个额外的ng-click指令.你不能在你的plunker看到它,尝试拷贝和粘贴在一个无格式的文本编辑器,如记事本.你会看到额外的 – 看起来像这样:
<button class="btn save-cat" id="{{testing}}" ng--click="doClick()">Save</button>
可能的原因可能是因为从html页面复制和粘贴代码到另一个页面,或者从不同的文档格式到html格式.
要解决这个问题,只需创建一个具有相同内容的按钮元素,不要复制并粘贴该按钮元素.
在我的DEMO中,您将看到两个具有相同标记的按钮,第一个按钮不起作用,而另一个按钮正常工作.