0
我正在嘗試使用Angular構建一個小型投資組合項目,我使用ng-repeat重複了我的投資組合中的項目。但我只想要1(第一個)項目展示。我在側欄中有一個小導航,我希望能夠點擊項目中的項目。我對Angular完全陌生,但到目前爲止,我已經閱讀了路由和模板,但我不想使用外部html文件。任何建議都非常感謝!Angular.js單擊json數據數組?
的Javascript:
var app = angular.module('myPortfolio', []);
var pageContent = [
{
displayOrder: 1,
name: 'Project 1',
description: "Some description",
images: ["img/portfolio/feat_image_1.jpg"]
},
{
displayOrder: 2,
name: 'Project 2',
description: "A second description",
images: ["img/portfolio/feat_image_2.jpg"]
},
{
displayOrder: 3,
name: 'Project 3',
description: "A third description",
images: ["img/portfolio/feat_image_3.jpg"]
}
];
app.controller("portfolioController", function($scope) {
this.projects = pageContent;
});
HTML:
<div ng-controller="portfolioController as myPortfolio">
<!-- various html page header etc. -->
<div class="row" ng-repeat="project in myPortfolio.projects">
<div class="large-2 columns" id="sidebar">
<h1>{{project.name}}</h1>
<p>{{project.description}}</p>
<div class="row side-nav-div">
<div class="large-4 columns project-nav">
<button type="button" class="slick-prev slick-disabled left">Previous</button>
</div>
<div class="large-4 columns project-nav centered">
</div>
<div class="large-4 columns project-nav">
<button type="button" class="slick-next slick-disabled right" ng-click="">Next</button>
</div>
<div style="clear:both"></div>
</div>
</div>
<div class="large-10 columns" id="main-section">
<div class="slider1">
<div class="feature-img" ng-repeat="image in project.images">
<img ng-src="{{image}}"/>
</div>
</div>
</div>
</div>
</div>
感謝您的信息!這對於菜單非常有用,但我試圖想到一種單擊數據的方式,通過點擊ng數單擊 – conor909
來加載對象中的下一個項目。你想在哪裏?點擊並顯示什麼,請稍微清楚一下你想要達到什麼 –
對不起,如果它不夠清楚。我希望能夠點擊項目數組中的數據對象。通過點擊project-nav元素(next和previous按鈕) – conor909