私はAngular.JSが初めてで、現在最初のプロジェクトに取り組んでいます。この種のエントリでいっぱいのページがあります
<h1>Title</h1>
<p>Teaser</p>
<p>(a link)</p>
&
. 私がやりたいことは、このティーザーを「解析」して、ブラウザー (現在は Google Chrome) がフォーマットを適切に「理解」できるようにすることです。
詳細ページの場合、id が showews に渡されますが、最初の呼び出しにはすべてのニュースを読み取るための ID がありません。ユーザーは各ニュース リンクから詳細ページにアクセスできます。ここで、私はすでに同じ問題を抱えています。以下に、メイン ニュース ページと詳細ページの両方の Angular.JS コードを示します。ここでは、ng-bind-html
次のようにディレクティブを使用して詳細ページの問題を解決できます。
$scope.shownews = function(id) {
if (typeof id === 'undefined') {
$http({
method: 'GET',
url: 'http://dev.ivm.at/getallnews.php'
}).
success(function(data, status, headers, config) {
$scope.allnews = data;
$scope.myHTML = [];
for (var i = 0; i < $scope.allnews.length; i++) {
$scope.myHTML[i] = $scope.allnews[i].Teaser;
}
});
} else {
$http({
method: 'GET',
url: 'http://dev.ivm.at/getnews.php?ID=' + id
}).
success(function(data, status, headers, config) {
$scope.singlenews = data;
$scope.Newstitel = $scope.singlenews[0].Title
//[...]
$scope.Inhalt = $scope.singlenews[0].Inhalt;
//[...]
$scope.myHTML = "<h1>" + $scope.Newstitel + "</h1><br>" + $scope.Inhalt;
});
}
}
<div data-role="page" id="allnews">
<div id="sub">
<section class="blog">
<article ng-bind-html="myHTML" ng-repeat="news in allnews">
<h1>{{news.Title}}</h1>
<p>{{myHTML[$index]}}</p>
<p class="readmore">
<a href="onenews" ng-click="shownews(news.ID)">
Weiterlesen: {{news.Title}}
</a>
<span class="readmore_icon"></span>
</p>
</article>
</section>
</div>
</div>
私の質問は、コマンドがテキストの配列である場合にng-bind-html
解析するように、コマンドを適切に使用する方法です。$scope.myHTML
ご回答ありがとうございます。