【问题标题】:Is it possible to render html and send json to the angular scope in one response?是否可以在一个响应中呈现 html 并将 json 发送到角度范围?
【发布时间】:2014-11-16 10:25:42
【问题描述】:

简单的例子。当然它不起作用,但请抓住这个想法:

router.get('/', function(req, res){
  Users.find ( {name: "John"}, function (err, users) {
      res.{ json: users, render: 'index' };
  });
});

是否可以在一个响应中发送 json 数据并渲染 html?

此外,我想同时将 用户 发送到 angular $scope。

有可能吗?

【问题讨论】:

  • 最好不要混合数据和模板。模板的获取次数不应超过一次。我通常构建 Angular 应用程序的方式是使用像 github pages 这样的静态服务器,该服务器始终 24/7 全天候运行,并且在某些服务器上具有 REST api

标签: json angularjs node.js http express


【解决方案1】:

试试这样的:

res.render('your view',{
                foo : 'bar'
            });

【讨论】:

    猜你喜欢
    • 2018-02-26
    • 2013-04-11
    • 2021-03-15
    • 2016-11-20
    • 1970-01-01
    • 2017-03-10
    • 1970-01-01
    • 2016-08-21
    • 1970-01-01
    相关资源
    最近更新 更多