我嘗試了許多不同的事情來試圖讓它起作用。 我已閱讀:Angular ng-click not firing
ng-click not firing in AngularJS while onclick does
AngularJS : ng-click not working
和更大量
HTML:
<div ng-controller="testApp">
<div id="bla">
<button ng-click="obey('bla')">Close</button>
<h4>Bla bla bla</h4>
</div>
</div>
JS:
var testApp = angular.module('testApp', []);
testApp.controller('testController', function($scope) {
$scope.obey = function test(id) {
$("#" + id).fadeOut("slow", function() {
this.remove()
});
};
});
出於某種原因,div完全不會淡出。
只是一個提示,你應該避免DOM操作,而使用AngularJS請參考:http://stackoverflow.com/questions/14994391/thinking-in-angularjs-if-i-have-a-jquery-background 。使用AngularJS時,jQuery不是必需/推薦。 – lin