webserviceを使用するjsファイルがあります。ここでは、ng-repeat指令で使用したい配列を定義します。 これは異なるファイルの角度指令を使用してjsファイルで定義された変数にアクセスする
<article ng-repeat="article in scopeArticles">
<h1 class="content">content is {{article.title}} </h1>
<img src="{{article.imgSource}}" href="{{article.source}}"/>
<p>{{article.description}}</p>
</article>
JSが
var articles = [];
$(document).ready(function() {
$.ajax({
url: "https://newsapi.org/v1/articles?source=google-news&sortBy=top&apiKey=001034455"
}).then(function (data) {
$.each(data.articles, function (key, value) {
articles.push({
title: value.title,
description: value.description,
source: value.url,
imgSource: value.urlToImage,
date: value.publishedAt
});
})
})
});
'scopeArticles'と' articles'が異なる変数です! –
また、 '$ .ajax'の代わりに' $ http'サービス(コントローラ内部)を使用すると、より角度のあるやり方で見えるようになります。 –