这是小提琴:http: //jsfiddle.net/yFyxL/2/
angular.module("myApp", []) //
.controller('MainController', function($scope) {
$scope.toggle1 = function() {
$scope.$broadcast('event:toggle');
}
$scope.toggle2 = function() {
$scope.$broadcast('event:toggle');
}
}) //
.directive('toggle', function() {
return function(scope, elem, attrs) {
scope.$on('event:toggle', function() {
elem.slideToggle();
});
};
});
因此,单击 toggle1 或 toggle2 将同时打开两个容器。但我想独立切换它们。我怎样才能做到这一点?