在我的控制器中我有这个代码,我从html模板中的一个表中获取id并从服务中获取一个对象并返回到ngDialog以显示编辑此数据并保存在我的api-rest中:
(function() {
'use strict';
angular
.module('app')
.controller('FraseController', FraseController);
FraseController.$inject = ['FraseService','ngDialog'];
function FraseController(FraseService,ngDialog) {
var vm = this;
vm.texto = rpeuba;
vm.iden = 0;
vm.efrase = '';
vm.edit = function(){
FraseService.get().then(function(response){
console.log(response.data.response);
vm.efrase = response.data.response;
ngDialog.open({
template: 'newFrase',
scope: this
});
});
}
}
}());
并在此HTML代码中:
<script type="text/ng-template" id="newFrase">
<h1>Nueva Frase {{vm.texto}}</h1>
<div class="modal-body">
<div class="row">
<div class="form-group">
<label for="frase" class= "col-lg-2 espaciar">Frase: </label>
<div class="col-lg-10">
<input ng-model="frase.efrase.frace" type="text" name="frase" id="frase" class="form-control" placeholder="Escriba su frace aquí">
</div>
<br>
<label for="autor" class= "col-lg-2 control-label espaciar">Autor: </label>
<div class="col-lg-10 ">
<input type="text" name="autor" name="autor" class="form-control" placeholder="Escriba el Autor aquí">
</div>
<br>
<label class="col-lg-2 espaciar">Banner: </label>
<div class="col-lg-10">
<select name="banner" class="form-control selectize-input espaciar">
<option value="0"><< Ninguno >></option>
<option ng-repeat="itemb in FraseController.lbanner" value="{{itemb.id}}">
{{itemb.titulo}}
</option>
</select>
</div>
</div>
</div>
</div>
<div class="modal-footer">
<button type="button"
class="btn btn-default"
ng-click="closeThisDialog('tiempo')">Cancelar</button>
<input name="submit" value="Insertar" class="btn btn-primary" title="Insertar" type="submit">
</div>
</script>
我想在我的ngDialog中显示来自我的控制器的数据以编辑一个Frase
答案 0 :(得分:0)
早上好,这里是如何用ngDialog解决我的所有问题。 当我为我所谓的ngDialog.openConfirm运行答案时,在响应上运行我的控制器方法,并作为参数传递一个消耗数据的对象。 这是我删除frase的代码。 JS在我的控制器中:
vm.drop = function(__frase){ //Drop the frase
ngDialog.openConfirm({
template: '<h3>You are sure to delete the phrase<h3> '+
'<div class="modal-footer"> '+
'<button type="button" '+
'ng-click=closeThisDialog("Cancel") '+
'class="btn btn-default">Cancel'+
'</button> '+
'<button type="button" '+
'ng-click=confirm(dfrase.frase.id) '+
'class="btn btn-primary">Delete</button> '+
'</div>',
plain:true,
controllerAs: 'dfrase',
controller: [function() {
var vm = this;
vm.frase = __frase;
}]
})
.then(
function(value) { //ok
FraseService.drop(value).then(function(response) {
console.log(response.data.response);
});
refresh();
},
function(value) { //cancel
console.log(value);
}
);
}
FraseService使用者是与我的api和refresh方法交互的因素,刷新了frase列表项。 D问候