1
取得したコンテンツを未加工htmlでajaxで表示しようとしています。この部分はhtmlタグを受け入れない取得したデータをraw htmlのanglejsで表示できません
<html ng-app="fetch">
<head>
<title>Вывод с базы</title>
<link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.24/angular.min.js"></script>
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular-sanitize.js"></script>
</head>
<body>
<br>
<div class="row">
<div class="container">
<h1>С базы вывод</h1>
<div ng-controller="dbCtrl">
<input type="text" ng-model="searchFilter" class="form-control">
<table class="table table-hover">
<thead>
<tr>
<th>News title</th>
<th>News description</th>
</tr>
</thead>
<tbody>
<tr ng-repeat="news in data | filter:searchFilter">
<td>{{news.title}}</td>
<td ng-bind-html='data'>{{news.description}}</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
</body>
<script>
angular.module('fetch', ['ngSanitize']).controller('dbCtrl', ['$scope', '$http', function ($scope, $http) {
$http.get("/ajax.php")
.success(function(data){
$scope.data = data;
})
.error(function() {
$scope.data = "error in fetching data";
});
}]);
</script>
</html>
しかし<td ng-bind-html='data'>{{news.description}}</td>
の出力: は、ここに私の一つのファイル内のコードです。 出力は次のとおりです。[オブジェクト、オブジェクト]となど
はここに私のajax.php
私は私のモジュールに角度-サニタイズとngSanitizeを追加しました<?php
//database settings
$conn=new mysqli("1", "1", "1", "1");
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
mysqli_query($conn, "SET NAMES utf8mb4");
$result = mysqli_query($conn, "select * from rss where source='tengrinews.kz' limit 20");
$data = array();
while ($row = mysqli_fetch_array($result)) {
$data[] = $row;
}
echo json_encode($data);
?>
だ、問題は何ですか?
をあなたの実際のデータは.data'フィールド 'になります:あなたはそれを表示するためにJSON filter(それ以外の場合は
[object Object]
としてレンダリングされます)と新しいセルを作成<td>
を使用する必要があります。スコープ変数へのデータの割り当てを '$ scope.data = data.data; 'に変更してください。 – Chinni@Chinniいいえ、動作しません。タイトルにはHTMLタグがなく、簡単に表示され、説明もHTMLタグで表示されます。もし、ng-bind-html属性/ – ATIKON
を削除すると、まずこの - > '