javascript - 如何使用 ng-click 传递 php 变量

标签 javascript php html angularjs

我有一个使用 php 的 foreach 循环,在该循环中传递了三个参数。问题是,当我执行控制台日志时,传递给控制台的变量显示未定义,但在 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 View 源,我可以看到所有三个值。

    $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>

关于javascript - 如何使用 ng-click 传递 php 变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32131240/

相关文章:

javascript - 帮助 jQuery 动画

javascript - z 在 translate3d 中

javascript - 具有未知数量变量的 AJAX 帖子

php - bootstrap/Wordpress 中每行 3 个元素

html - Jquery模态插件

javascript - 如何在单元格5之后动态添加行vue.js

javascript - 错误 : Illegal arguments: undefined, 字符串

php - 使用空间分析功能和数据类型在 MySQL 中按距离排序

html - 水平和垂直居中 HTML 对象

javascript - chrome 是否限制请求帧时间