I have the following scenario: I have a modal call directive and I want to pass another policy as content, the code is as follows:
maintain-provider-form.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;
};
}]);
code snippet calling 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 the template:
<modal titulo="tituloModal" corpo="corpoModal" is-mostrar="isMostrarModal"></modal>
result obtained:
How do I print the maintain-provider-form directive within the modal?