Reputation: 179
I am working on MVC trying to pass id on click button from HTML to JS my code where i am creating table in HTML is,
<tbody>
<tr ng-repeat="Survey in vm.AllSurveys">
<td>{{Survey.visitNumber}} </td>
<td>{{Survey.id}}</td>
<td>
<button id="myButton" onclick="myFunction('{{Survey.id}}');">Home</button>
</td>
</tr>
</tbody>
On click function is like,
function myFunction(id) {
console.log(id);
location.href = "http://localhost/Test?visitId="+id;
}
I have data in this format,
[{VisitNumber: "Visit_U_1", id: "107"},... So on]
But i got this error in html onclick line,
Error: [$compile:nodomevents] http://errors.angularjs.org/1.3.9/$compile/nodomevents
at https://ajax.googleapis.com/ajax/libs/angularjs/1.3.9/angular.min.js:6:416
at pre
<button id="myButton" onclick="myFunction('{{Survey.id}}');">
I tried solutions but did not get success Hopes for your suggestions
Upvotes: 0
Views: 1281
Reputation: 375
You can use ng-click directive to pass data like below code
<button id="myButton" ng-click="myFunction(Survey.id);">Home</button>
Upvotes: 1