1
我是AngularJS的新手。這是我的第一個Plunker。如何在AngularJS中按類索引div?
我想使它如此以便如果用戶單擊節中的鏈接,鏈接的值將顯示在結果中。其他兩個結果應該清除它們的值。
我找不到任何關於如何通過索引引用類中的特定項目的文檔。在jQuery中,我通常會做這樣的事情......
// get this index of the thing that was clicked
$this = $(this),
Idx = $BUTTONS.BigButtons.index($this),
ThisButton.eq(Idx).doSomething();
<body ng-controller="MainController as main">
<div class="title" ng-repeat="i in [1,2,3]">
<p>This is section {{i}}</p>
<ul>
<li ng-repeat="j in [1,2,3]">
<a href="" ng-click="main.displayContent(i, j)">section {{i}} - link {{j}}</a></li>
</ul>
<div class="results" ng-bind="main.results"></div>
</div>
</body>
var app = angular.module('controllerAsDemo', []);
app.controller('MainController', function() {
this.results = "Lame default";
this.displayContent = function(firstIdx, secondIdx) {
this.results = "populate section "
+ firstIdx
+ " with the number "
+ secondIdx
+ " - other two results should be empty"
;
};
});
這裏是Demo
太棒了!我還沒有看到任何你提供的例子。它似乎正是我所需要的。非常感謝!!! –
不客氣。請記住,Angular會爲你操控dom。如果你不得不操縱DOM來完成某些事情,那麼你可能會做錯某些事情。 – Alok