Answer the question
In order to leave comments, you need to log in
Why doesn't ng-click work when generating html when from a jQuery function?
for (var i = 0; i < categories.length; i++) {
if (categories[i]=="Home") {
$("#categoryNav").append("<a class=\"btn btn-primary\" ng-click=\"app.changeList('')\">" + categories[i] + "</a>");
}
else {
$("#categoryNav").append("<a class=\"btn btn-primary\" ng-click=\"app.changeList('" + categories[i] + "')\">" + categories[i] + "</a>");
}
}
app.controller("ProductsController", function ($http) {
var goga = this;
goga.changeList = function (category) {
$http.get('/api/DataService/' + category)
.success(function (results) {
goga.products = results;
});
};
});
<a class="btn btn-primary" ng-click="app.changeList('Soccer')">TEST</a>
Answer the question
In order to leave comments, you need to log in
Most likely the problem is not in the correct sequence of script execution, i.e. angular is initialized faster than jquery generates buttons.
You are clearly using angular incorrectly and the buttons need to be built using angular.
Are you using noConflict()? And then you can’t say so in your code. jQuery and angular don't get along
Angular has a provider called $compile. https://docs.angularjs.org/api/ng/service/$compile
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question