繁体   English   中英

我无法使用节点js使用angularjs将Json的数据注入html

[英]i can't inject data from Json into html with angularjs using node js

我无法将Json文件中的数据注入到html中。 我得到了很好的回应,我可以将其登录到我的回应的 chrome console.log中

但我无法将其注入我的html中。

这是我的angularJs代码:

 <p ng-bind-html="essaiJson.titre"></p>


var app = angular.module('monApp', ['ngSanitize']);
app.controller('monControl', function($scope, $http, $compile){

    $scope.maVariable = "MEAN Stack";


    $http.get('/JavaScript/mean.json')
    .then(function(response){
        $scope.essaiJson = response.data;
        console.log($scope.essaiJson);
    });

当我登录$ scope.essaiJson.titre时,我得到了很好的响应,但是当我绑定它时,什么也没有!

我的node.js代码:

var express = require('express'),
    app = express(),
    http = require('http').createServer(app);

app.get('/', function (req, res) {
    res.sendFile(__dirname + '/app/ex11.html');
});

http.listen(8080);

使用<p>{{essaiJson.titre}}</p>

而不是<p ng-bind-html="essaiJson.titre"></p>

ng-bind-html计算表达式,然后以安全的方式将结果HTML插入元素。

就您而言,您只需要将json数据绑定到您的html中,就可以使用

<p>{{essaiJson}}</p>

这是您要达到的目标的一个示例: https ://stackblitz.com/edit/angularjs-cuhtns

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM