我们使用两个指令来使用http从服务器获取不同的数据。我们将$ emit事件发送到其他指令,如果用户选择其他指令,速度$ emit会在这里崩溃。
First Directive
app.directive('dealStages', ['$filter', '$rootScope', '$timeout', function($filter, $rootScope, $timeout) {
return {
restrict: 'E',
replace: true,
templateUrl: staticResourseUrl + '/html/pages/Deal/_deal-stages.html',
scope: {
'stages': '=',
'id': '=',
'scount': '='
},
link: function(scope, elemn, attr, rootScope) {
scope.$watch('scount', function(newVal, oldVal) {});
scope.$watch('stages', function(newVal, oldVal) {});
scope.newContent = {};
//scope.isChecked = utilSrv.isChecked;
scope.getRadioChecked = scope.$parent.getRadioChecked;
scope.loadQMDetails = function(e, qm) {
////console.log('inside load QM');
$timeout(function() {
//$scope.$broadcast("onSomething", "");
scope.$emit('open', "true", e, qm);
}, 1000);
//scope.$broadcast('open', true, e);
//scope.openQMModal = true;
};
}
}
}]);
Second Directive
app.directive('showQM', ['$rootScope', '$filter', '$timeout', '$window', '$document', '$location', 'dealService', 'utilSrv', 'errorModalService',
function($rootScope, $filter, $timeout, $window, $document, $location, dealService, utilSrv, errorModalService) {
return {
restrict: 'E',
replace: true,
scope: {
setFn: '&',
getTimeline : '&',
stages: '=',
nextSteps: '=',
notifications: '='
},
link: function(scope, elemn, attr) {
// $rootScope.$broadcast('elastic:adjust');
scope.activeStone;
scope.callfromDirective = function(obj, qm){
//console.log('inside');
scope.qm_id = qm.id;
scope.getAttachments(qm.id);
scope.getQMNotes();
scope.qmDetails = qm;
scope.qmDetails.deadlineFormat = $filter('date')(scope.qmDetails.deadline, 'd MMM, yyyy');
scope.editQM = scope.qmDetails;
//console.log('==== before qmDetails====' + JSON.stringify(scope.qmDetails));
//console.log('==== before qmDetails 3333====' + JSON.stringify(scope.editQM));
scope.showDetailsDiv(obj);
};
$rootScope.$on('open', function(someData, e, obj, qm) {
//////console.log('whole stone'+JSON.stringify(qm));
scope.qm_id = qm.id;
scope.getAttachments(qm.id);
scope.getQMNotes();
//scope.Label = false;
scope.qmDetails = qm;
scope.qmDetails.deadlineFormat = $filter('date')(scope.qmDetails.deadline, 'd MMM, yyyy');
scope.editQM = scope.qmDetails;
console.log('show the values'+JSON.stringify(qm));
scope.showDetailsDiv(obj);
//$(".noteEdittextarea").flexible();
});
}
]);
第一个指令在循环中创建不同的div,用户可以使用第二个指令单击每个div上的打开模态窗口。如果用户只需打开一个模态窗口并在那里进行一些操作并快速点击其他div来打开新模态然后它就会破坏。