angular.js - How to get the id in angularjs to achieve the purpose of deletion?
仅有的幸福
仅有的幸福 2017-05-15 17:00:42
0
2
643
<p style="width: 450px;float: left;margin-left: 50px">

    <table>
        <!-- 这里以name为排序标准  -->
        <tr ng-repeat="x in users | orderBy : 'name'">

            <!-- $index显示序列号,从1开始  -->
            <td>{{ $index + 1 }}</td>
            <td>{{ x.id }}</td>

            <!-- 把英文转为大写  -->
            <td>{{ x.name |uppercase }}</td>
            <td>{{ x.password }}</td>
            <td>{{ x.email }}</td>
            <td><input type="button" value="编辑" onclick="editUser()"/></td>
            <td><input type="button" value="删除" onclick="deleteUser(x.id)"/></td>
        </tr>
    </table>

How to get the id here
onclick="deleteUser(x.id)"
This won't work, and adding {{}} won't work either.

It was a bit confusing just opening angularjs....

After obtaining, how to call the controller method?

This is a method in the controller, so calling it like this doesn’t seem to work...

    function deleteUser(userID) {

        alert(userID);

    }
仅有的幸福
仅有的幸福

reply all(2)
伊谢尔伦

Why use the native oneonclick?你应该用angular 的ng-clickah

PHPzhong

Resolved:

Use ng-click to call.
The calling function is:
$scope.deleteUser = function (userID) {

    console.log(userID);
    alert(userID);

}
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template