在你,gedContextMenu.js
文件,做如下更改
進樣pluginApp
angular.module('gedContextMenuApp', ['ui.bootstrap', 'mgcrea.ngStrap.popover','pluginApp']);
進樣服務customSvc
在gedContextMenu
菜單指令,
angular.module('gedContextMenuApp').directive('gedContextMenu',['$log','$templateCache', '$uibModal', 'customSvc', function($log, $templateCache, $uibModal, customSvc) {
return {
restrict: 'AE',
scope: {
gedContextData: '='
},
template: "<button class='fa fa-cog' bs-popover data-template='{{popoverTemplate}}' data-auto-close='1' data-placement='bottom' data-animation='am-flip-x'></button>",
controller: function($scope) {
$scope.popoverTemplate = 'popoverTemplate.html';
$scope.executePlugin = function($event, contextItem) {
var propName = contextItem.action;
$scope.contextItem = contextItem;
$log.info('property name ' + propName + ' used to trigger event ', $event.type);
$scope[propName] = $event;
}
$scope.click = function($event, contextItem) {
$scope.executePlugin($event, contextItem);
}
},
link: function(scope, element, attrs) {
scope.$watch('openDialog', function(event) {
if (event && event.type === 'click') {
console.log(customSvc);
// var customSvc = angular.injector(['ng', 'pluginApp']).get("customSvc");
//angular.injector(['ng', function($provide) {
// var $rootElement = angular.element(document.querySelector('body'));
// $provide.value('$rootElement', $rootElement);
//}]).invoke(function($injector) {
// var localRootElement = $injector.get('$rootElement');
//});
// customSvc.testOpenDialog(100, scope);
//customSvc.testDirettivaConfirm(100, scope);
}
});
}
}
}]);
你想在你的指令訪問「customSvc」服務,對不對? – Aparna
我已經通過angular.injector函數訪問它,它的工作原理是,問題在sampleDirective中,因爲在那裏,ng-include不起作用 – Dragos
在sampleDirective中,爲什麼你要在模板中使用ng-include,包括沒有擴展名模板:「
」,請使用templareUrl:「sampleLinkTemplate.html」 – Aparna