I have checked all the solutions available here, but it didn't help me.
I am trying to display a button from AngularJs to html, but ng-click
is not working for <a>
or <button>
tags. I am working in Eclipse and it contains many built in modules. Please help me out. Below is the sample code:
<!DOCTYPE html>
<html>
<head>
<script src= "http://ajax.googleapis.com/ajax/libs/angularjs/1.2.26/angular.min.js"></script>
</head>
<body>
<div ng-app="" ng-controller="contrl">
<a href="" ng-click="testFunc1()">Link1</a>
<div id="id1">Text1</div>
<p id="id2">Text2</p>
</div>
<script>
function contrl($scope,$http,$location){
xyz = '<button type="submit" ng-click="testFunc2()">Link2</button>';
document.getElementById("id1").innerHTML = xyz;
$scope.testFunc1 = function() {
document.getElementById("id2").innerHTML = "abc";
};
$scope.testFunc2 = function() {
document.getElementById("id2").innerHTML = "xyz";
};
}
</script>
</body>
</html>
Only ng-click
attribute is not working when I pass it through angularJs. Even href
attribute is working in the same case. As i am using Eclipse all the required modules are already setup in different files. I was working with angularJs from two weeks and everything was working except when I faced this issue.
{{id2}}
Output is:
– Prash Mar 09 '15 at 04:39