How to get an html content in modal-body - angularjs

I'm having trouble passing a html (form) for body modal.
Use the modal as a service, and have a standard template for the modal. If not past the template will of course use the default. And thus fail to repeat code.Then I wanted to go into the modal only the content that will be passed in scope.
modal.service.js
(function() {
var app = angular.module('app');
function ModalService($rootScope, $q, $modal) {
var defaultOptions = getModalDefaultOptions();
var service = {
showModal: showModal
};
return service;
function getModalDefaultOptions() {
return {
templateUrl: '/app/shared/modals/templates/modal.default.html',
closeButtonText: 'Fechar',
actionButtonText: 'OK',
headerTitle: 'Header default',
bodyContent: 'Conteúdo body modal',
showActionButton: true,
showCloseButton: true,
headerClass: ''
};
}
function showModal(customModalOptions) {
var deferred = $q.defer();
//Create temp objects to work with since we're in a singleton service
var tempModalOptions = {};
//Map modal.html $scope custom properties to defaults defined in service
angular.extend(tempModalOptions, defaultOptions, customModalOptions);
var scope = $rootScope.$new();
scope.modalOptions = tempModalOptions;
scope.modalOptions.ok = function(result) {
deferred.resolve();
modal.hide();
};
scope.modalOptions.close = function(result) {
deferred.reject();
modal.hide();
};
var modal = $modal({
scope: scope,
templateUrl: scope.modalOptions.templateUrl,
title: scope.modalOptions.headerTitle,
content: scope.modalOptions.bodyContent,
show: true
});
console.log(tempModalOptions);
return deferred.promise;
}
}
app.factory('ModalService', ModalService);
})();
modal.default.html
<div class="modal" role="dialog" tabindex="-1" data-type="Modal Default">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header" data-ng-class="modalOptions.headerClass" ng-show="title">
<button class="close" ng-click="modalOptions.close();" type="button">×</button>
<h4 class="modal-title" ng-bind="modalOptions.headerTitle"></h4>
</div>
<div class="modal-body" ng-bind="modalOptions.contentTemplate">{{modalOptions.contentTemplate}}</div>
<div class="modal-footer">
<button class="btn btn-default" data-ng-click="modalOptions.close();" data-ng-show="modalOptions.showCloseButton" type="button">
{{modalOptions.closeButtonText}}</button>
<button class="btn btn-primary" data-ng-click="modalOptions.ok();" data-ng-show="modalOptions.showActionButton">
{{modalOptions.actionButtonText}}</button>
</div>
</div>
</div>
</div>
entidades.controller.js
(function() {
'use strict';
var app = angular.module('app');
app.controller('EntidadesController', EntidadesController);
function EntidadesController(EntidadeService, ModalService) {
var vm = this;
vm.entidades = JSON.parse(EntidadeService.getAll());
vm.openEditEntidades = function() {
ModalService.showModal({
headerClass: 'danger',
contentTemplate: '/app/modulos/entidades/views/edit-entidades.html'
})
.then(function() {
alert('Alert Modal 2');
});
};
// console.log('Entidades onDemand');
}
})();
The view that calls the modal
<section ng-controller="EntidadesEditCtrl as ctrl">
<div class="modal-header">
<h3 class="modal-title">Editando entidade</h3>
</div>
<div class="row">
<div class="modal-body">
<form novalidate class="form-inline">
<div class="col-md-6">
<div class="form-group">
<label class="sr-only" for="fm_name">Email address</label>
<input class="form-control" id="fm_name" ng-model="vm.entidade.name" type="text">
</div>
<div class="form-group">
<label class="sr-only" for="fm_email">Email</label>
<input class="form-control" id="fm_email" ng-model="vm.entidade.email" type="email">
</div>
<div class="form-group">
<label class="sr-only" for="fm_sexo">Sexo</label>
<input class="form-control" id="fm_sexo" ng-model="vm.entidade.gender" type="text">
</div>
<div class="form-group">
<label class="sr-only" for="fm_companhia">Companhia</label>
<input class="form-control" id="fm_companhia" ng-model="vm.entidade.company" type="text">
</div>
</div>
<div class="col-md-6">
<div class="form-group">
<label class="sr-only" for="fm_id">User ID</label>
<input class="form-control" id="fm_id" ng-model="vm.entidade._id" type="text">
</div>
<div class="form-group">
<label class="sr-only" for="fm_phone">Telefone</label>
<input class="form-control" id="fm_phone" ng-model="vm.entidade.phone" type="tel">
</div>
<div class="form-group">
<label class="sr-only" for="fm_endereco">Endereço</label>
<input class="form-control" id="fm_endereco" ng-model="vm.entidade.address" type="text">
</div>
<div class="checkbox">
<label>
<input type="checkbox" ng-model="vm.entidade.isActive">{{vm.entidade.isActive}}
</label>
</div>
</div>
</form>
</div>
</div>
<br>
<div class="modal-footer">
<button class="btn btn-primary" ng-click="ctrl.update(vm.entidade); vm.ok()" type="button">OK</button>
<button class="btn btn-warning" ng-click="vm.cancel()" type="button">Cancel</button>
</div>
</section>
and the content to be inserted into body-modal
<div class="row" ng-controller="EntidadesController as ectrl">
<div class="row text-center">
<h1>Gerenciar entidades</h1>
</div>
<hr>
<div class="row col-md-10 col-md-offset-1">
<table class="table table-striped" st-table="rowCollection">
<thead>
<div class="panel ">
<div class="panel-heading">
<button class="btn btn-default pull-right" ng-click="open()">Add</button>
<div class="clearfix"></div>
</div>
</div>
<tr>
<th>#</th>
<th>Nome</th>
<th>Compania</th>
<th>Telefone</th>
<th>email</th>
<th>ação</th>
</tr>
</thead>
<tbody>
<tr ng-repeat="entidade in ectrl.entidades">
<td>{{entidade._id}}</td>
<td>{{entidade.name}}</td>
<td>{{entidade.company}}</td>
<td>{{entidade.phone}}</td>
<td>{{entidade.email}}</td>
<td>
<button class="btn btn-default" ng-click="ectrl.openEditEntidades(entidade)" type="button">
Editar
</button>
</td>
</tr>
</tbody>
<tfoot>
<tr>
<td class="text-center" colspan="5">
<div st-displayed-pages="7" st-items-by-page="itemsByPage" st-pagination=""></div>
</td>
</tr>
</tfoot>
</table>
</div>
</div>
Thanks for u time.

You should use ng-include to insert another template.
<div class="modal" role="dialog" tabindex="-1" data-type="Modal Default">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header" data-ng-class="modalOptions.headerClass" ng-show="title">
<button class="close" ng-click="modalOptions.close();" type="button">×</button>
<h4 class="modal-title" ng-bind="modalOptions.headerTitle"></h4>
</div>
<div class="modal-body" ng-include="modalOptions.contentTemplate"></div>
<div class="modal-footer">
<button class="btn btn-default" data-ng-click="modalOptions.close();" data-ng-show="modalOptions.showCloseButton" type="button">
{{modalOptions.closeButtonText}}</button>
<button class="btn btn-primary" data-ng-click="modalOptions.ok();" data-ng-show="modalOptions.showActionButton">
{{modalOptions.actionButtonText}}</button>
</div>
</div>
</div>
</div>

Related

Data edit - modal Bootstrap

I have a problem with editing data in the bootstrap modal.
The problem is that in the modal, only first record from the database is displayed.
Modal only displays the problem because it retrieves data from 1 record.
Could it show me something wrong with the code, that it only gets 1 record for me?
My code AngularJS:
controllersAdmin.controller('linkEdit', function( $scope, $http, $routeParams, $timeout){
var linkID = $routeParams.id;
$scope.id = linkID;
$scope.link = function( link ){
$http({
method: 'GET',
url: 'api/admin/links/get/' + linkID,
}).then(function (response){
$scope.link = response.data.records;
},function (error){
console.log('Blad we wczytywaniu danych');
});
}
$scope.saveChanges = function( link ){
$http({
method: 'POST', url: 'api/admin/links/update/', data: {'link' : link}},
).then(function (){
$scope.success = true;
},function (error){
console.log('Blad we wczytywaniu danych');
});
}
});
<tr ng-repeat="link in link">
<td>{{$index+1}}</td>
<td>{{link.links | limitTo:50}}...</td>
<td>{{ link.login }}</td>
<td>{{link.password}}</td>
<td>{{link.date}}</td>
<td>
<button ng-click="deleteLink(link, $index)" class="btn btn-danger">×</button>
<button data-toggle="modal" ng-click="edtlnk(link)" data-target="#edit-data" class="btn btn-primary">Edit</button>
<div class="modal fade" id="edit-data" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
<div class="modal-dialog" role="document">
<div class="modal-content">
<form method="POST" name="editlinke" role="form" ng-submit="saveChanges( link )">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
<h4 class="modal-title" id="myModalLabel">Edit Item</h4>
</div>
<div class="modal-body">
<div class="container">
<div class="row">
<div class="col-xs-12 col-sm-6 col-md-6">
<div class="form-group">
<input type="text" class="form-control" ng-model="link.login">
<input type="text" class="form-control" ng-model="link.password">
<input type="text" class="form-control" ng-model="link.links">
</div>
</div>
</div>
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
<button type="submit" class="btn btn-primary">Submit</button>
</div>
</div>
</form>
</div>
</div>
</div>
</td>
</tr>

Angularjs upload image

I'm trying to create an upload function using angularjs. I have watch and read few tutorials in the internet. Unfortunately all the tutorials are too complicated for me because I'm still new in this field.
<form ng-submit="upload(currentUser())">
<div class="row">
<div class="form-group">
<div class="col-xs-2">
<label>Car</label>
</div>
<div class="col-xs-5">
<input type="text" placeholder="Perodua Myvi" class="form-control" ng-model="newCar" required>
</div>
<div class="col-xs-5"></div>
</div>
</div>
<div class="row">
<div class="form-group">
<div class="col-xs-2">
<label>Price(RM) per day</label>
</div>
<div class="col-xs-5">
<input type="text" placeholder="80" class="form-control" ng-model="newPrice" required>
</div>
<div class="col-xs-5"></div>
</div>
</div>
<div class="row">
<div class="form-group">
<div class="col-xs-2">
<label>Business Area</label>
</div>
<div class="col-xs-5">
<input type="text" placeholder="Universiti Malaysia Sabah" class="form-control" ng-model="businessArea" required>
</div>
<div class="col-xs-5"></div>
</div>
</div>
<div class="row">
<div class="form-group">
<div class="col-xs-2">
<label>Insert Car Image</label>
<br>
</div>
<div class="col-xs-5">
<!--<button type="button" class="btn btn-default btn-sm">
<span class="glyphicon glyphicon-picture"></span> Image
</button>-->
<input type="file"/>
</div>
<div class="col-xs-5"></div>
</div>
</div>
<div class="row">
<div class="form-group">
<div class="col-xs-2">
</div>
<div class="col-xs-5">
<button type="submit" class="btn btn-primary btn-sm pull-right">
<span class="glyphicon glyphicon-globe"></span> Publish
</button>
</div>
<div class="col-xs-5"></div>
</div>
</div>
<br>
<br>
</form>
app.controller('postadCtrl', [
'$scope',
'auth',
function($scope, auth) {
$scope.currentUser = auth.currentUser;
$scope.posts = [];
$scope.upload = function(user) {
$scope.posts.push({
company_name: user,
car_type: $scope.newCar,
seaters: 5,
price: $scope.newPrice,
contact: 038880000,
location: $scope.businessArea
});
};
}
]);
So how do I do this in the simplest form and explanation? And how does my router and module will look like?
The output should look like this.

Why ng-click is not working in my angular datatable?

I do now know, but I think jquery is conflicting with my angular datatable, but even when I take off jquery (hide and show elements), ng-click keeps not working.
Here goes as well a printscreen from my table:
My AngularJS js:
angular.module('BoxApp').controller("ConfiguraBkpEmail", function($scope, $http) {
var urlRestServer = "http://localhost:8080/boxmlV2";
$scope.clientes = {};
$scope.clientesSelecionados = {};
$scope.iniciar = function() {
$http.get(urlRestServer + '/configurabkpemail').success(function(response) {
$scope.clientes = response;
});
};
$scope.iniciar();
$scope.selecionaClientes = function(selecao){
$scope.clientesSelecionados = selecao;
$('#myModal').modal('show');
if($scope.clientesSelecionados.backupEmail == 0){
// $('#enderecoEmailBackup').hide();
// $('#idLabel').hide();
} else {
// $('#enderecoEmailBackup').show();
// $('#idLabel').show();
}
};
/**
* Trecho para validar o form ao submeter.
*/
$scope.submitted = false;
$scope.submitForm = function(form) {
$scope.submitted = true;
if (form.$valid) {
$scope.editaEmailBkp();
}
};
$scope.editaEmailBkp = function() {
var dados = {
idCliente : idCliente.value,
razaoSocial : razaoSocial.value,
backupEmail : $scope.clientesSelecionados.backupEmail,
enderecoEmailBackup : enderecoEmailBackup.value
};
$http.post(urlRestServer + '/configurabkpemail/salvar', dados).then(function(response) {
$scope.sucesso();
}, function(response) {
});
};
$scope.sucesso = function() {
$scope.closeModal();
$scope.iniciar();
};
$scope.closeModal = function() {
// $('#myModal').modal('hide');
};
$scope.opcoesBkps = [
{OpcaoBkpID: 0, Tipo: '0 - Sem backup de e-mail'},
{OpcaoBkpID: 1, Tipo: '1 - Backups inconsistentes'},
{OpcaoBkpID: 2, Tipo: '2 - Backup de Todos E-mails'}
];
});
My html:
<div class="row">
<table datatable="ng" id="configuraBkpEmail" class="row-border hover table table-striped table-bordered table-hover">
<thead>
<tr>
<th>Nome Empresa</th>
<th>CNPJ</th>
<th>Backup E-mail</th>
</tr>
</thead>
<tbody>
<tr ng-repeat="x in clientes" ng-click="selecionaClientes(x)">
<td><span ng-bind="x.razaoSocial" /></td>
<td><span ng-bind="x.cnpj" /></td>
<td><span ng-bind="x.strOpcaoBackupEmail" /></td>
</tr>
</tbody>
</table>
</div>
My modal that should be opened:
<!-- Modal INICIO-->
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">
×
</button>
<h4 class="modal-title" id="myModalLabel">Configuração Backup de E-mail</h4>
</div>
<div class="modal-body">
<div class="row">
<div class="col-md-12">
<f<div ultimate-datatable="datatable" width="100%"></div>orm name="form" id="form_sample_2" role="form"
class="form-horizontal ng-pristine ng-valid" novalidate>
<div class="form-group">
<label class="control-label col-md-3">Nome:<span
class="required" aria-required="true"> * </span></label>
<div class="col-md-9">
<input type="text"
ng-model="clientesSelecionados.razaoSocial"
class="form-control" id="razaoSocial" maxlength="100"
name="razaoSocial" required disabled> <span
style="color: red"
ng-show="submitted && form.razaoSocial.$error.required">Campo
Nome Obrigatório.</span>
</div>
</div>
<div class="form-group">
<label class="control-label col-md-3">Backup de
E-mail:<span class="required" aria-required="true"> *
</span>
</label>
<div class="col-md-9">
<select size="1" name="backupEmail"
ng-model="clientesSelecionados.backupEmail"
ng-change="selecionaClientes(clientesSelecionados)"
class="form-control"
ng-options="opcoesBkp.OpcaoBkpID as opcoesBkp.Tipo for opcoesBkp in opcoesBkps"
required>
<option value="">Selecione um Recurso.</option>
</select> <span style="color: red"
ng-show="form.backupEmail.$error.required">Selecione
uma opção de backup.</span>
</div>
</div>
<div class="form-group">
<label id="idLabel" class="control-label col-md-3">Endereço:<span
class="required" aria-required="true"> * </span>
</label>
<div class="col-md-9">
<input type="email"
placeholder="Endereço do Backup para encaminhamento."
ng-model="clientesSelecionados.enderecoEmailBackup"
class="form-control" id="enderecoEmailBackup"
maxlength="100" name="enderecoEmailBackup">
</div>
</div>
<div class="form-group">
<label id="idLabel" class="control-label col-md-3">ID:<span
class="required" aria-required="true"> * </span></label>
<div class="col-md-9">
<input type="text" ng-model="clientesSelecionados.idCliente"
class="form-control" id="idCliente" maxlength="100"
name="idCliente" disabled> <span
style="color: red"
ng-show="submitted && form.idCliente.$error.required">Campo
ID Obrigatório.</span>
</div>
</div>
</form>
</div>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">
Cancelar
</button>
<button type="submit" class="btn btn-primary" ng-click="submitForm(form)">
Salvar
</button>
</div>
</div><!-- /.modal-content -->
</div><!-- /.modal-dialog -->
</div><!-- /.modal -->
<!-- Modal FIM-->
Try ng-click="$parent.selecionaClientes(x)".

AngularJS: Passing data to modal from list

I am currently learning how to build a MEAN webapp from scratch. Stuff goes quite well until this point but now i am stuck at trying to pass data from my list (ng-repeat) to my modal via ng-click=updatePerson(person). I have absolutely no clue why I can't access the data from the list. I tried like 20 variants to link the data between both scopes without any success.
This is my Controller:
angular.module('userCtrl', ['userService','ui.bootstrap'])
.controller( 'userController', function(User, $uibModal, $log, $scope) {
var vm = this;
User.all().success( function(data) {
vm.users = data;
})
vm.deleteUser = function(id) {
User.delete(id).success(function(data) {
User.all().success(function(data) {
vm.users = data;
});
});
};
vm.createUser = function() {
User.create(vm.userData).success(function(data) {
vm.userData = {};
User.all().success(function(data) {
vm.users = data;
});
});
};
vm.updateUser = function(selectedUser) {
$scope.selectedUser = selectedUser;
var modalInstance = $uibModal.open({
animation: true,
templateUrl: 'app/views/pages/modal.html',
resolve: {
user: function () {
return $scope.selectedUser;
}
}
});
modalInstance.result.then(function(selectedUser) {
$scope.selected = selectedUser;
});
};
});
My angular-router:
angular.module('appRoutes', ['ngRoute'])
.config(function($routeProvider, $locationProvider) {
$routeProvider
.when('/', {
templateUrl : 'app/views/pages/home.html',
controller : 'userController',
controllerAs : 'user'
})
.when('/users', {
templateUrl : 'app/views/pages/user.html',
controller : 'userController',
controllerAs : 'user'
});
$locationProvider.html5Mode(true);
});
My list:
<div class="btn-group">
<button type="button" class="btn-lg btn-default glyphicon glyphicon-plus" data-toggle="modal" data-target="#createModal"></button>
<table class="table table-nonfluid table-bordered table-striped" ng-show="user.users">
<thead>
<tr>
<th></th>
<th>Vorname</th>
<th>Nachname</th>
<th>E-Mail</th>
</tr>
</thead>
<tbody>
<tr ng-repeat="person in user.users">
<td><button ng-click="user.deleteUser(person._id)" class="btn btn-default btn-lg glyphicon glyphicon-trash"></button></td>
<td>{{person.firstname}}</td>
<td>{{person.lastname}}</td>
<td>{{person.mail}}</td>
<td><button ng-click="user.updateUser(person)" class="btn btn-default btn-lg glyphicon glyphicon-trash"></button></td>
<!--<td><button class="btn-lg btn-default glyphicon glyphicon-option-horizontal" data-toggle="modal" data-target="#updateModal"></button> </td>-->
</tr>
</tbody>
</table>
<!--Create Modal-->
<div class="modal fade bs-example-modal-lg" id="createModal" tabindex="-1" role="dialog" aria-labelledby="myLargeModalLabel">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
<h4 class="modal-title" id="exampleModalLabel">Neue Person</h4>
</div>
<form id="form1" ng-submit="user.createUser()">
<div class="modal-body">
<div class="form-group">
<label for="recipient-name" class="control-label">Vorname</label>
<input type="text" class="form-control" ng-model="user.userData.firstname">
</div>
<div class="form-group">
<label for="recipient-name" class="control-label">Nachname</label>
<input type="text" class="form-control" ng-model="user.userData.lastname">
</div>
<div class="form-group">
<label for="recipient-name" class="control-label">E-Mail</label>
<input type="text" class="form-control" ng-model="user.userData.mail">
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Schließen</button>
<button id="button1" type="submit" class="btn btn-primary">Person erstellen</button>
</div>
</form>
</div>
</div>
</div>
</div>
<script type="text/javascript">
$('#button1').click(function() {
$('#createModal').modal('hide');
});
</script>
And here is my modal:
<div class="modal-content bs-example-modal-lg" role="dialog document">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
<h4 class="modal-title" id="exampleModalLabel">Ändere Person</h4>
</div>
<div class="modal-body">
<div class="form-group">
<label for="recipient-name" class="control-label">Vorname</label>
<input type="text" class="form-control" ng-model="person.firstname" placeholder={{person.firstname}}>
</div>
<div class="form-group">
<label for="recipient-name" class="control-label">Nachname</label>
<input type="text" class="form-control" ng-model="person.firstname" placeholder={{person.lastname}}>
</div>
<div class="form-group">
<label for="recipient-name" class="control-label">E-Mail</label>
<input type="text" class="form-control" ng-model="person.firstname" placeholder={{person.mail}}>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Schließen</button>
<button id="button1" type="submit" class="btn btn-primary">Person ändern</button>
</div>
</div>
The user you're resolving won't be bound to the view automatically. You need a controller to do that. You can use the code below, or you can use controllerAs, but you'd have to update the modal's HTML accordingly.
vm.updateUser = function(selectedUser) {
$scope.selectedUser = selectedUser;
var modalInstance = $uibModal.open({
animation: true,
templateUrl: 'app/views/pages/modal.html',
resolve: {
user: function () {
return $scope.selectedUser;
}
},
controller: function($scope, user) {
$scope.user = user;
}
});
modalInstance.result.then(function(selectedUser) {
$scope.selected = selectedUser;
});
};

how to call main controllers function from child directive in angularjs

I am not able to call method adddepartment which is in controller.I am calling this method from myCreateDialog.html.
My second directive in under the first directive. I am able to call departments method which is in controller from myDept directive. but not able to call adddepartment method of controller from myCreateDialog directive.
How do i call this method?
myApp.controller('departmentController', ['$scope', 'departmentService' ,
function ($scope, departmentService) {
$scope.departments = departmentService.departments;
var a, b;
//Add New Department
$scope.adddepartment = function (emps) {
departmentService.adddepartment(depts);
$scope.depts = "";
};
}]);
myApp.directive("myDept", function () {
return {
restrict: "E",
scope:{
department:"="
},
templateUrl: 'Template/Alldepartment.html',
replace: false,
transclude:true,
link: function (scope, element, attrs, controller) {}
};
});
myApp.directive("myCreateDialog", function () {
return {
restrict: "E",
scope:{
adddepartment: "&"
},
templateUrl: 'Template/myCreateDialog.html',
link: function (scope, element, attrs, controller) {
}
};
});
App.js
var myApp = angular.module("myApp", ['ngRoute']);
myApp.config(['$routeProvider',
function ($routeProvider) {
$routeProvider.
when('/Employee', {
templateUrl: 'Template/Employee.html',
controller: 'employeeController'
}).
when('/Department', {
templateUrl: 'Template/Department.html',
controller: 'departmentController'
})
}]);
Department.html
<my-dept department="departments">
<p>This text is coming by transclude</p>
</my-dept>
Alldepartment.html
<div>
<div class='myTransclude' ng-transclude></div>
<button class="btn btn-success" data-toggle="modal" data-target="#crtdept">
<span class="glyphicon glyphicon-plus-sign"></span> Create New Department
</button>
</div><br />
<!--Display department data into table-->
<div class="table-responsive">
<table class="table table-bordered table-striped table-hover ">
<thead>
<tr class="success ">
<th>Id</th>
<th>Name</th>
<th>Technology</th>
<th>Edit</th>
</tr>
</thead>
<tbody>
<tr ng-repeat="dept in department">
<td>{{dept.id}}</td>
<td>{{dept.name}}</td>
<td>{{dept.technology}}</td>
<td>
<button class="btn btn-link" title="Edit" data-toggle="modal" data-target="#editemp" ng-click="empedit(employee,employees.indexOf(employee))">
<span class="text-warning glyphicon glyphicon-pencil"></span> Edit 
</button>
<button class="btn btn-link" ng-click="deleteemp(employees.indexOf(employee))">
<span class=" text-danger glyphicon glyphicon-trash "> Delete</span>
</button>
</td>
</tr>
</tbody>
</table>
</div>
<!--myCreateDialog directive for showing dialog for creating department-->
<my-create-dialog adddepartment="adddepartment(depts)"></my-create-dialog>
myCreateDialog.html
<div class="modal fade" id="crtdept">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" style="color:red" class=" close" data-dismiss="modal"> ×</button>
<h4 class="modal-title">Create Employee</h4>
</div>
<div class="modal-body">
<form class="form-horizontal" data-toggle="validator" role="form" ng-submit="adddepartment(emps)">
<div class="form-group">
<label class="control-label col-sm-2" for="name">Name:</label>
<div class="col-sm-10 has-success">
<input type="text" class="form-control" placeholder="Enter Your Name" ng-model="emps.empnames" required>
</div>
</div>
<div class="form-group">
<label class="control-label col-sm-2" for="email">Email:</label>
<div class="col-sm-10 has-success">
<input type="email" class="form-control" id="email" placeholder="Enter Your email" ng-model="emps.empemails" required>
</div>
</div>
<div class=" form-group">
<label class="control-label col-sm-2">City:</label>
<div class="col-sm-10 has-success">
<input type="text" class="form-control" placeholder="Enter Your City" ng-model="emps.empcitys" required>
</div>
</div>
<div class="form-group">
<label class="control-label col-sm-2">Department:</label>
<div class="col-sm-10 has-success">
<input type="text" class="form-control" placeholder="Enter your Department" ng-model="emps.empdepts" required>
</div>
</div>
<div class="form-group">
<label class="control-label col-sm-2">Technology:</label>
<div class="col-sm-10 has-success">
<input type="text" class="form-control" placeholder="Enter your Technology" ng-model="emps.emptechs" required>
</div>
</div>
<div class="form-group">
<div class="col-sm-offset-2 col-sm-10">
<button type="submit" class="btn btn-success"><span class="glyphicon glyphicon glyphicon-ok"></span> Create</button>
</div>
</div>
</form>
<div class="modal-footer">
<button type="button" class="btn btn-danger" data-dismiss="modal"> Close</button>
</div>
</div>
</div>
</div>
</div>
You can inject your departmentService into your directive and call it from there
myApp.directive("myCreateDialog", function (departmentService) {
return {
restrict: "E",
templateUrl: 'Template/myCreateDialog.html',
link: function (scope, element, attrs, controller) {
scope.adddepartment = function (emps) {
departmentService.adddepartment(depts);
scope.depts = "";
};
}
};
});

Resources