我是Angularjs和Nodejs的新手。我在使用AngularJs单击按钮后尝试调用card.html页面。此外,card.html页面应显示" scope.resultCards"从控制器获得。我应该如何实现同样的目标?任何帮助/建议将受到高度赞赏。谢谢!
我的html页面如下所示:
<div id ="button_spaces">
<table>
<tbody>
<tr ng-repeat="result in results">
<br>
<form action="/card">
<td> <input type ="submit" ng-click="getcards(result.setIdNum)" value = {{result.Category}} >
</td>
</form>
</tr>
</tbody>
</table>
</form>
</div>
</div>
我的客户控制器如下: $ scope.getcards = function(setIdNum){
var url = "/cards/"+setIdNum;
console.log(" cards url "+ url);
$http.get(url).success(function(data){
$scope.resultCards = data;
console.log("Test cards: ", $scope.resultCards);
});
}
我的server.js代码如下: app.get(&#39; / cards /:setIdNum&#39;,function(req,res){
var searchrequest = req.params.setIdNum;
Cards.find({settIdNum: searchrequest},function(err, found) {
if (err)
res.send(err)
else
res.json(found); // return all cards in JSON format
});
});
答案 0 :(得分:0)
使用$state.go
使用参数重定向到另一个视图,请参阅UI Router的官方文档
$scope.getcards = function(setIdNum) {
var url = "/cards/"+setIdNum;
console.log(" cards url "+ url);
$http.get(url).success(function(data){
$scope.resultCards = data;
console.log("Test cards: ", $scope.resultCards);
$state.go("card", { cards: $scope.resultCards });
});
}