萬一要是我錯了,給我正確的方式去做
我試圖從ng-repeat
通過index
和item
名。它沒有解決某個問題。任何人都可以幫我排序嗎?
這裏是代碼:
<div class="wrapper" ng-app="myApp">
<div class="content" ng-controller="main">
<h2 ng-class="active">{{activeItem.name}}</h2>
<sub-title item='item' index=$index ng-repeat="item in items" change="changeItem()"></sub-title>
</div>
</div>
// Code goes here
var app = angular.module('myApp', []);
app.controller('main', ["$scope", function($scope) {
console.log("cotroller")
$scope.items = [{"name":'one'},{"name":'two'},{"name":'three'}, {"name":'four'},{"name":'five'},{name:'six'}];
$scope.activeItem = $scope.items[0];
$scope.queueItems = $scope.items.splice(0,1);
$scope.changeItem = function (index, item) {
console.log("change now", index, item.name); //not consoling
}
}]);
app.directive("subTitle", function() {
return {
replace:true,
scope:{
change :'&',
item : '=',
index:'='
},
template : '<h2>{{item.name}} {{index}}</h2>',
link : function (scope, element, attrs) {
var num = scope.index;
element.on('click', function() {
scope.change(num, item);
})
}
}
})
請給我們您的html標記 – miensol
請檢查,我已經添加了現場演示 – user2024080
'h2'沒有變化事件。你想要達到什麼目的? – Satpal