4
I have the following scenario: I have a directive called modal and I want to pass another directive as content, the code is as follows:
maintain-supplier-formulario.js
"use strict";
angular.module("fornecedor")
.directive('manterFornecedorFormulario', function () {
return {
restrict: 'EA',
templateUrl: '/Marcenaria/Scripts/App/Directive/Fornecedor/manter-fornecedor-formulario.html',
link: function(scope,elm,attrs){
},
scope:{
msgSucesso: '=',
msgError: '=',
msgInfo: '='
},
controller: "manterFornecedorCtrl",
controllerAs : "mFornCtrl"
}
});
angular.module("fornecedor")
.controller("manterFornecedorCtrl", ["$scope", "$http", "$timeout", "request", "tools", function ($scope, $http, $timeout, request, tools) {
var self = this;
$scope.loadingAjax = false;
this.limpar = function () {
$scope.Nome = "";
$scope.Contato = "";
$scope.Telefone = "";
$scope.msgSucesso = "";
$scope.msgError = "";
$scope.msgInfo = "";
};
this.salvar = function () {
$scope.msgSucesso = "";
$scope.msgError = "";
var msg = "";
if (tools.IsNullOrEmpty($scope.Nome)) {
msg += "O campo Nome está em branco! \n";
}
if (msg.length == 0) {
if (!$scope.loadingAjax) {
$scope.loadingAjax = true;
console.log("ID para alterar: "+$scope.Id);
request._post("/Marcenaria/Fornecedor/Salvar", {
Nome: $scope.Nome,
Telefone: $scope.Telefone,
Contato: $scope.Contato,
Id: $scope.Id
})
.then(function (data) {
$scope.msgSucesso = "Forncedor inserido com sucesso.";
$scope.loadingAjax = false;
}, function (erro) {
$scope.msgError += "ERRO: " + erro;
$scope.loadingAjax = false;
});
}
} else {
$scope.msgError = msg;
}
};
}]);
modal.html
<div class="example-modal" ng-if="isMostrar">
<div class="modal modal-primary">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" ng-click="modalCtrl.fechar()" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
<h4 class="modal-title">{{titulo}}</h4>
</div>
<div class="modal-body">
{{corpo}}
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default pull-left" data-dismiss="modal" ng-click="modalCtrl.fechar()">Fechar</button>
{{botoes}}
</div>
</div>
</div>
</div>
</div>
modal.js
"use strict";
angular.module("layout")
.directive('modal', function () {
return {
restrict: 'EA',
templateUrl: '/Marcenaria/Scripts/App/Directive/Layout/modal.html',
scope: {
titulo: '=',
isMostrar: '=',
corpo: '='
},
controller: "modalCtrl",
controllerAs: "modalCtrl"
}
});
angular.module("layout")
.controller("modalCtrl", ["$scope", "$http", "$timeout", "request", "tools", function ($scope, $http, $timeout, request, tools) {
var self = this;
$scope.isMostrar = true;
this.fechar = function () {
$scope.isMostrar = false;
};
this.abrir = function () {
$scope.isMostrar = true;
};
}]);
excerpt from the code that calls the modal:
angular.module("fornecedor")
.controller("pesquisarFornecedorCtrl", ["$scope", "$http", "$timeout", "request", "tools", function ($scope, $http, $timeout, request, tools) {
var self = this;
var msg = "";
$scope.loadingAjax = false;
$scope.fornecedores = [];
$scope.tituloModal = "Editar Fornecedor";
$scope.corpoModal = "<manter-fornecedor-formulario></manter-fornecedor-formulario>";
...
called in template:
<modal titulo="tituloModal" corpo="corpoModal" is-mostrar="isMostrarModal"></modal>
result obtained:
How I print the keep-vendor-form directive within the modal ?
In case I won’t need the id="modalcontent", right ?
– Mayllon Baumer
That, you can take!
– Diullian
Success, Thank you.
– Mayllon Baumer