Extends angular materials dialog service with .showAbrisComponentDialog(). This method takes the name of a directiva as a parameter and will inject that directive into the dialog. This can be useful when you don't want to create a template and controller for a dialog when all that you want is to show a directive in it. The service uses ngIncludeComponent in to dynamically inject the directive into the dialog template.
bower install md-component-dialog --save
var app = angular.module('app', ['abrissirba.mdComponentDialog']);
$mdDialog.showAbrisComponentDialog({
componentName: 'userComponent',
title: 'User',
params: {
user: {
name: 'Marcus Abrahamsson',
city: 'Linköping',
country: 'Sweden'
}
},
clickOutsideToClose: true
}).then(function(res){
});
angular
.module('angularMdComponentDialog')
.directive('userComponent', function User() {
return {
scope: {
user: '=',
onOk: '=?',
onCancel: '=?',
},
templateUrl: 'app/components/user.html',
link: function (scope) {
scope.ok = function () {
$log.log("ok");
if(scope.onOk){
scope.onOk();
}
}
}
}
}
<div>
{{user | json}}
</div>
<md-button ng-click="onCancel()">Cancel</md-button>
<md-button ng-click="ok()">ok</md-button>
mdComponentDialog uses the same options as the regular .show() method plus the following
Type String
The name of the directive that should be used within the dialog. The name should be in camelCase;
Type String
The title that should be used in the dialog toolbar
Type any
An object that holds the parameters that should be injected into the directive scope.
mdComponentDialog will provide two callback methods to the directive it injects into its template. These should be called if you want to close the dialog and resolve the dialog promise.
Call this if you want to resolve the dialog promise
Call this if you want to reject the dialog promise