我有一个使用 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/