我有一个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)表示该值未定义。现在,我做错了为什么不能获得这些价值观?
答案 0 :(得分:1)
您应该添加"
。
试试这样:
<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>