search

Home  >  Q&A  >  body text

angular.js - How to get the id in angularjs to achieve the purpose of deletion?

<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);

    }
仅有的幸福仅有的幸福2868 days ago676

reply all(2)I'll reply

  • 伊谢尔伦

    伊谢尔伦2017-05-15 17:02:42

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

    reply
    0
  • PHPz

    PHPz2017-05-15 17:02:42

    Resolved:

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

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

    reply
    0
  • Cancelreply