我想在我的Ionic App中为问题报告构建一个全局模式。 在我的应用程序的几个页面中,我有一个"报告问题"应该打开包含表单的模式的按钮。
每个页面(带有问题描述的表单)的模式完全相同,但是我希望有时将附加数据传递给它。 IE:
要求:
理想情况下,每个控制器中唯一的代码应该是
.controller('Ctrl', function($scope, $issueModal){
$scope.reportIssue = function(){
$issueModal.show({item_id: 42});
}
});
我试过this implementation,但由于这些原因我不满意:
感谢任何给我指示的人!
答案 0 :(得分:0)
您所描述的内容可以通过使用角度来完成$ $提供服务来装饰ionModalDirective。
这是一个使用ionActionSheetDirective覆盖模板的示例,但是如果你不想覆盖模板那么也没关系,你可以根据传入的参数覆盖链接函数。这完全取决于你。这里的关键是,无论何时在应用程序中使用ionModal,结果模板,链接函数等都将提供给角度。:
angular.module('ionic').config(['$provide', function ($provide) {
$provide.decorator('ionActionSheetDirective', ['$delegate', function ($delegate) {
var directive = $delegate[0];
// Here we are completely overriding the template definition for the ionActionSheetDirective
directive.template = '' +
'<div class="action-sheet-backdrop action-sheet-backdrop-fisdap">' +
'<div class="action-sheet-wrapper">' +
'<div class="action-sheet">' +
'<div class="action-sheet-group action-sheet-group-title" ng-if="titleText">' +
'<div class="action-sheet-title" ng-bind-html="titleText"></div>' +
'</div>' +
'<div class="action-sheet-group action-sheet-group-buttons">' +
'<button class="button button-outline" ng-click="buttonClicked($index)" ng-repeat="button in buttons" ng-class="button.classes" ng-bind-html="button.text"></button>' +
'<button class="button button-outline button-assertive destructive" ng-click="destructiveButtonClicked()" ng-bind-html="destructiveText" ng-if="destructiveText"></button>' +
'<button class="button button-outline button-balanced" ng-click="cancel()" ng-bind-html="cancelText" ng-if="cancelText"></button>' +
'</div>' +
'</div>' +
'</div>' +
'</div>';
// Store the old compile function
var compile = directive.compile;
// Overwrite the old compile function
directive.compile = function () {
// Get the link function from the old directive
var link = compile.apply(this, arguments);
// If we wanted to add some elements programatically we'd do it here
// tElement.append('<div>Added in the decorator</div>');
// Use the link function from the old directive for this directive
return function () {
link.apply(this, arguments);
// We can extend the link function here if we wanted to
};
};
return $delegate;
}]);
}]);