如何使用ng-click传递一个PHP变量

how to pass a php variable using ng-click

本文关键字:一个 PHP 变量 何使用 ng-click      更新时间:2023-09-26

我有一个foreach循环使用php在循环中传递三个参数。问题是,当我做一个控制台日志变量被传递到控制台说没有定义,但在HTML中,我可以看到HTML输出与变量在那里。

这是我的html

<tbody><?php
   foreach($rows as $row):?>
       <tr class="odd gradeA">
            <td><a href="#"><?=$row->firstName?> <?=$row->lastName?></a></td>
            <td><?=$row->address . ' ' . $row->city . ' ' . $row->state . ' ' . $row->zipCode?></td>
            <td><?=$row->email?></td>
            <td><?=$row->cellPhone?></td>
            <td class="text-right tableIcons">
                <a title="Edit User" href="users/edit/<?=$row->userId?>" class="btn btn-primary btn-xs"><i class="fa fa-pencil"></i></a>
                <button ng-click="remove(<?=$row->firstName?>, <?=$row->lastName?>, <?=$row->userId?>)" title="Remove User" href="#" class="userRemove btn btn-danger btn-xs"><i class="fa fa-trash"></i></button>
            </td>
       </tr><?php
   endforeach?>
</tbody>

当我按下ng-click时,我想要得到这3个参数被传递。在HTML视图源中,我可以看到这三个值。

    $scope.remove = function(firstName, lastName, userId){
    console.log(firstName);
    $scope.firstName = firstName;
    $scope.lastName = lastName;

    var modalInstance = $modal.open({
        animation: $scope.animationsEnabled,
        templateUrl: 'remove.html',
        controller: function($scope, $modalInstance){
            $scope.cancel = function () {
                $modalInstance.dismiss('cancel');
            };
        }
    })
};

console.log(firstName)表示该值未定义。现在我做错了什么,为什么不能得到这些值?

您应该添加"

试试:

        <button ng-click="remove('<?=$row->firstName?>', '<?=$row->lastName?>', '<?=$row->userId?>')" title="Remove User" href="#" class="userRemove btn btn-danger btn-xs"><i class="fa fa-trash"></i></button>