【问题标题】:moving from hogan to angular after data received from server从服务器接收到数据后从 hogan 移动到 angular
【发布时间】:2015-07-19 06:14:35
【问题描述】:

我已将我的app.engine 设置为 hogan,并且我使用的是 express 路由器,所以这就是我用来呈现数据的方式:

   router.get('/upcoming_events', securePages, function(req, res, next){
            res.render('upcoming_events', {title: 'Welcome to aDating - Upcoming Events', users:users});
    })

在我的 HTML 页面中,我会像这样访问数据 h2>{{users}}</h2>

现在问题是 {{users}} 包含 Json 格式的内容,我想用 angular 处理它...我该怎么做?谢谢

【问题讨论】:

    标签: angularjs node.js express hogan.js


    【解决方案1】:

    JSON.parse(valid_json); 会将你的 json 字符串变成一个 JS 对象。


    详细地说,如果您使用$http 从您的 Express 应用程序中获取数据,这就是它的样子。

    $scope.getStuff = function () {
      $http.get(apiHost + '/upcoming_events').then(function (res) {
        return JSON.parse(res.data.upcoming_events);
        // { title: 'Welcome to aDating - Upcoming Events', users: [ /** a collection of users, I presume? **/ ] }
      });
    };
    

    【讨论】:

      猜你喜欢
      • 2017-02-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-06-25
      • 2020-01-10
      • 2019-04-13
      • 1970-01-01
      相关资源
      最近更新 更多