【问题标题】:redirect to a different html page using angularJs and Nodejs使用 angularJs 和 Nodejs 重定向到不同的 html 页面
【发布时间】:2016-09-03 11:55:12
【问题描述】:

我是 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('/cards/:setIdNum', 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

    });
}); 

【问题讨论】:

  • 您好 Dipali,您需要在点击后重定向页面吗?
  • 嗨西瓦。是的,单击按钮后,我需要重定向到另一个页面(card.html),该页面将显示($scope.resultCards)中的内容

标签: angularjs node.js


【解决方案1】:

使用$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 });
        });
    }

【讨论】:

  • 感谢 Siva 的帮助。我实际上是通过使用 $location.path(url) 解决的。
猜你喜欢
  • 2013-09-07
  • 2014-06-24
  • 1970-01-01
  • 1970-01-01
  • 2018-08-20
  • 2012-06-18
  • 1970-01-01
  • 1970-01-01
  • 2014-10-25
相关资源
最近更新 更多