嗨,我在同一页面上有两个弹出指令。问题是当我单击一个时,它们都会弹出。
如何将每个范围相互隔离,以便仅弹出单击的弹出窗口?
HTML
<popup class="popup">
<trigger>
<a href="#" data-ng-click="showPopup()">Show Popup</a>
</trigger>
<pop>
I popped up
</pop>
</popup>
<popup class="popup">
<trigger>
<a href="#" data-ng-click="showPopup()">Show Popup</a>
</trigger>
<pop>
I popped up too
</pop>
</popup>
popup.js
angular.module('sembaApp')
.directive('popup', function () {
return {
restrict: 'E',
replace: true,
transclude: true,
template: '<div data-ng-transclude></div>',
controller: function postLink($scope, $element, $attrs) {
$scope.popup = false;
$scope.showPopup = function() {
$scope.popup = !$scope.popup;
}
}
}
})
.directive('trigger', function () {
return {
require: '^popup',
restrict: 'E',
replace: true,
transclude: true,
template: '<div data-ng-transclude></div>',
}
})
.directive('pop', function () {
return {
require: '^popup',
restrict: 'E',
replace: true,
transclude: true,
template: '<aside data-ng-transclude data-ng-show="popup"> yay</aside>'
}
});