0

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

3
  • change your button's onclick to onclick="myFunction(Survey.id)" ? Commented Apr 11, 2019 at 8:03
  • getting this error Uncaught ReferenceError: Survey is not defined Commented Apr 11, 2019 at 8:08
  • change your html with <button id="myButton" ng-click="myFunction(Survey.id);">Home</button> angularjs controller : $scope.myFunction = function(id){console.log(id)}; Commented Apr 11, 2019 at 9:52

1 Answer 1

1

You can use ng-click directive to pass data like below code

<button id="myButton" ng-click="myFunction(Survey.id);">Home</button>
Sign up to request clarification or add additional context in comments.

2 Comments

It must by using it some way but not getting error it seems like it is not calling method
myFunction function must be in your angularjs controller, then it will call the method.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.