Я играю с использованием uibModal с завода вместо того, чтобы использовать его из своего контроллера. Диалоговое окно появляется, и данные поля возвращаются в службу при нажатии OK, но я не знаю, как вернуть данные к моему контроллеру, где он будет добавлен в мою модель. Любые указатели?
Вот мой завод код:
'use strict';
angular.module('ngTableScopeApp')
.factory('DialogService', function($uibModal){
var DialogService = {};
DialogService.newObj = {};
DialogService.addNewItem = function(template, $q){
this.modalInstance = $uibModal.open({
templateUrl: template,
controller: function($scope, $uibModalInstance){
$scope.ok = function() {
$uibModalInstance.close($scope);
return this.newObj;
};
$scope.cancel = function() {
$uibModalInstance.dismiss('cancel');
return null;
};
}
});
};
return DialogService;
});
Вот код контроллера:
'use strict';
/**
* @ngdoc function
* @name ngTableScopeApp.controller:MainCtrl
* @description
* # MainCtrl
* Controller of the ngTableScopeApp
*/
angular.module('ngTableScopeApp')
.controller('MainCtrl', function (NgTableParams, DummyData, DialogService) {
var self = this;
self.data = DummyData.generateData(1);
var createUsingFullOptions = function() {
var initialParams = {
count: 10 // initial page size
};
var initialSettings = {
// page size buttons (right set of buttons in demo)
counts: [5, 10, 25, 50],
// determines the pager buttons (left set of buttons in demo)
paginationMaxBlocks: 13,
paginationMinBlocks: 2,
dataset: self.data //DummyData.generateData(1)
};
return new NgTableParams(initialParams, initialSettings);
};
self.customConfigParams = createUsingFullOptions();
self.addNewItem = function(){
DialogService.addNewItem('views/addNewItem.html', self);
};
});
Надеюсь, что вы можете получить доступ к данным из контроллера с помощью D переменная ialogService.newObj. –