ng-repeat를 사용하여 객체 배열을 반복하는 방법을 파악하려고합니다.ng-repeat의 표현식은 어떻게 작동합니까?
나는 세 세트 데이터와 함께, 다음과 같이 설정 공장을 가지고 :
mainApp.factory("dashboardContent", function() {
return {
contentBoxes: [
{
boxType: "image",
boxIcon: "icons-image",
boxTitle: "on Chapter 1, paragraph 3",
header: {
title: "Lorem ipsum title sit amet",
subtitle: "by Lorem Ipsum"
},
authorImage: "/asssets/ssfsgterwes",
embedContent: ""
},
{
boxType: "audio",
boxIcon: "icons-audio",
boxTitle: "on Chapter 12, paragraph 2",
header: {
title: "lorem ipsum audio sit maet",
subtitle: "by multiple objects"
},
authorImage: "/asssets/ssfsgterwes",
embedContent: ""
},
{
boxType: "quote",
boxIcon: "icons-lightbulb",
boxTitle: "on Chapter 01, paragraph 5",
header: {
title: "lorem ipsum quote sit maet",
subtitle: "by multiple objects parsing"
},
authorImage: "/asssets/ssfsgterwes",
embedContent: ""
}
]
}
})
내가 공장 주입 한 지시문 : 내 관점에서
.directive('contentBox', function(dashboardContent) {
return {
restrict: 'E',
scope: {},
replace: true,
templateUrl: '/modules/contentbox.html',
link: function (scope, element) {
scope.contentData = dashboardContent.contentBoxes;
if (!$.isEmptyObject(scope.contentData.header)) {
element.children('.content').prepend(
'<div class="content-header">' +
'<span class="content-title">' +
scope.contentData.header.title +
'</span>' +
' <br/>' +
'</div>'
);
if (!$.isEmptyObject(scope.contentData.header.subtitle)) {
element.find('.content-header').append(
'<span class="content-author">' +
scope.contentData.header.subtitle +
'</span>'
);
}
}
}
}
})
을 나는 이것을 다음과 같이 반복하려고합니다.
<content-box ng-repeat="content in contentData"></content-box>
이 경우에 사용할 표현식은 무엇입니까? 나는이 표현이 어떻게 동작 하는지를 ng-repeat 문서에서 이해할 수 없다. contentData의 "content"에서 contentData는 내 객체 집합을 참조하지만, 첫 번째 단어는 무엇인가? 여기), 그것이 무엇을 참조합니까?
또한이 범위를 올바르게 설정 했습니까? 위의 코드에서와 같이 :
나는이에서지고있어 출력은 세 개의 빈 컨텐츠 상자, 그래서 내가 그것을 통해 반복 것 같은데요,하지만 데이터가 그들에 인쇄되고 있지
scope.contentData = dashboardContent.contentBoxes;
- 즉, {{ contentData.boxTitle}} 그냥 비어 있습니다.
이 상황에서 ng-repeat를 올바르게 사용하고 있습니까?
당신은 ng-repeat를 올바르게 사용하고 있습니다. 잘 모르겠지만이 같은 반복적 인 작업은'link'보다는'compile'을 사용해야합니까? –