如何使用 Angular 控制器将变量传递到另一个页面?
How to Pass variable to another page using Angular controller?
我有一个 HTLM table,其中包含有关人员的信息(id、name、..)。我把这个名字作为另一个页面的 link,所以当我按下任何人的名字时,我想将这个人的 ID 传递给另一个 php 页面以使用它。
下面是我的代码:
HTML:
<tr ng-repeat="x in data | filter:search:restrict">
<td>{{ x.id }}</td>
<td><button ng-controller ="direct" class="btn btn-link" ng-click = "sendID(x.id)">{{ x.name }}</button></td>
控制器:
fetch.controller('direct',function($scope,$http,$window){
$scope.sendID=function(){
$http.post("here.php",{'id':$scope.id})
.success(function(headers,config){
});
$window.location.href = '/here.php';
}
});
第二个页面,我想把id传给:
<?php
$data = json_decode(file_get_contents("php://input"));
echo $data->id;
?>
当我点击任何按钮时,第二页显示:
"Notice: Trying to get property of non-object"
知道哪里出了问题吗?!
谢谢。
可能是通过 href 传递 id:
$window.location.href = '/here.php?id=' + $scope.id;
PHP
<?php
$id = $_GET['id'];
echo $id;
?>
如果您只想在下一页访问它,请将其作为查询字符串传递
否则将值保存在 $rootscope 中,以便可以从任何控制器访问它
我有一个 HTLM table,其中包含有关人员的信息(id、name、..)。我把这个名字作为另一个页面的 link,所以当我按下任何人的名字时,我想将这个人的 ID 传递给另一个 php 页面以使用它。 下面是我的代码:
HTML:
<tr ng-repeat="x in data | filter:search:restrict">
<td>{{ x.id }}</td>
<td><button ng-controller ="direct" class="btn btn-link" ng-click = "sendID(x.id)">{{ x.name }}</button></td>
控制器:
fetch.controller('direct',function($scope,$http,$window){
$scope.sendID=function(){
$http.post("here.php",{'id':$scope.id})
.success(function(headers,config){
});
$window.location.href = '/here.php';
}
});
第二个页面,我想把id传给:
<?php
$data = json_decode(file_get_contents("php://input"));
echo $data->id;
?>
当我点击任何按钮时,第二页显示:
"Notice: Trying to get property of non-object"
知道哪里出了问题吗?!
谢谢。
可能是通过 href 传递 id:
$window.location.href = '/here.php?id=' + $scope.id;
PHP
<?php
$id = $_GET['id'];
echo $id;
?>
如果您只想在下一页访问它,请将其作为查询字符串传递 否则将值保存在 $rootscope 中,以便可以从任何控制器访问它