mirror of
https://github.com/ionic-team/ionic-framework.git
synced 2026-03-13 10:22:08 +08:00
Working modal stuff
This commit is contained in:
37
js/ext/angular/src/service/ionicModal.js
vendored
Normal file
37
js/ext/angular/src/service/ionicModal.js
vendored
Normal file
@@ -0,0 +1,37 @@
|
||||
angular.module('ionic.service.modal', ['ionic.service'])
|
||||
|
||||
|
||||
.factory('Modal', ['$rootScope', '$document', '$compile', 'TemplateLoader', function($rootScope, $document, $compile, TemplateLoader) {
|
||||
return {
|
||||
/**
|
||||
* Load a modal with the given template string.
|
||||
*
|
||||
* A new isolated scope will be created for the
|
||||
* modal and the new element will be appended into the body.
|
||||
*/
|
||||
fromTemplate: function(templateString) {
|
||||
// Create a new isolated scope for the modal
|
||||
var scope = $rootScope.$new(true);
|
||||
|
||||
// Compile the template
|
||||
var element = $compile(templateString)(scope);
|
||||
$document[0].body.appendChild(element[0]);
|
||||
|
||||
return new ionic.views.Modal({el: element[0] });
|
||||
},
|
||||
fromTemplateUrl: function(url, cb) {
|
||||
TemplateLoader.load(url).then(function(templateString) {
|
||||
// Create a new isolated scope for the modal
|
||||
var scope = $rootScope.$new(true);
|
||||
|
||||
// Compile the template
|
||||
var element = $compile(templateString)(scope);
|
||||
$document[0].body.appendChild(element[0]);
|
||||
|
||||
var modal = new ionic.views.Modal({ el: element[0] });
|
||||
|
||||
cb(modal);
|
||||
});
|
||||
}
|
||||
};
|
||||
}]);
|
||||
17
js/ext/angular/test/service/ionicModal.unit.js
Normal file
17
js/ext/angular/test/service/ionicModal.unit.js
Normal file
@@ -0,0 +1,17 @@
|
||||
describe('Ionic Modal', function() {
|
||||
var modal, q;
|
||||
|
||||
beforeEach(module('ionic.ui.modal'));
|
||||
|
||||
beforeEach(inject(function(Modal, $q) {
|
||||
q = $q;
|
||||
modal = Modal;
|
||||
}));
|
||||
|
||||
iit('Should show', function() {
|
||||
var template = '<div class="modal"></div>';
|
||||
var deferred = q.defer();
|
||||
modal.fromTemplate(template);
|
||||
deferred.resolve(true);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user