Angularjs 关闭md对话框后将项推送到数组不工作
通过md对话框推送项后,数组不会刷新,尽管我可以正常保存该项 我尝试测试可以手动将项目推入阵列的级别,直到Angularjs 关闭md对话框后将项推送到数组不工作,angularjs,angular-material,Angularjs,Angular Material,通过md对话框推送项后,数组不会刷新,尽管我可以正常保存该项 我尝试测试可以手动将项目推入阵列的级别,直到$scope.showAddUsuario()之后,我才能将项目推入阵列,即使是手动: Usuario.html <div flex-gt-sm="100" flex-gt-md="100" ng-controller="UsuarioCtrl"> <h2 class="md-title inset">Usuario</h2> <md
$scope.showAddUsuario()
之后,我才能将项目推入阵列,即使是手动:
Usuario.html
<div flex-gt-sm="100" flex-gt-md="100" ng-controller="UsuarioCtrl">
<h2 class="md-title inset">Usuario</h2>
<md-card>
<md-list>
...
</md-list>
</md-card>
<md-button class="md-fab" aria-label="Add" ng-click="showAddUsuario($event)">
<md-icon md-svg-icon="content:ic_add_24px" aria-label="Plus"></md-icon>
</md-button>
</div>
直到现在,我才看到您使用的是$mdDialog,而不是$modal。所以这个答案很可能不适用于你的情况 但是,您的代码中似乎缺少了
.finally()
部分。
从手册()
所以你可以试试。
否则,您是否考虑过改用$modal
您似乎没有处理来自您的modal的信息返回
(function (){
'use strict';
function myCtrl($modal){
var vm = this;
vm.myArray = [];
...
function openModal(){
var modalInstance = $modal.open({
templateUrl: 'path/to/modal/view.html',
controller: 'MyModalCtrl as vm',
size: 'lg',
resolve: {
data: function(){
return dataThatYouWantToSendFromHereToYourModal;
}
}
});
modalInstance.result.then(function (result){
vm.myArray.push(result);
});
}
...
}
...
})();
当您在模态控制器中(在本例中为MyModalCtrl
)发出$modalInstance.close(将此数据包发送到CallingController)
调用时,modalInstance.result.然后将触发
所以模态控制器应该沿着
...
function MyModalCtrl($modalInstance, data){
...
function init(){
doSomethingWithDataThatYouGotFromTheCallingController(data);
}
...
function save(){
var dataToSendBack = {...};
$modalInstance.close(dataToSendBack);
}
...
}
...
这将使您朝着正确的方向前进。直到现在,我才看到您使用的是$mdDialog,而不是$modal。所以这个答案很可能不适用于你的情况
但是,您的代码中似乎缺少了.finally()
部分。
从手册()
所以你可以试试。
否则,您是否考虑过改用$modal
您似乎没有处理来自您的modal的信息返回
(function (){
'use strict';
function myCtrl($modal){
var vm = this;
vm.myArray = [];
...
function openModal(){
var modalInstance = $modal.open({
templateUrl: 'path/to/modal/view.html',
controller: 'MyModalCtrl as vm',
size: 'lg',
resolve: {
data: function(){
return dataThatYouWantToSendFromHereToYourModal;
}
}
});
modalInstance.result.then(function (result){
vm.myArray.push(result);
});
}
...
}
...
})();
当您在模态控制器中(在本例中为MyModalCtrl
)发出$modalInstance.close(将此数据包发送到CallingController)
调用时,modalInstance.result.然后将触发
所以模态控制器应该沿着
...
function MyModalCtrl($modalInstance, data){
...
function init(){
doSomethingWithDataThatYouGotFromTheCallingController(data);
}
...
function save(){
var dataToSendBack = {...};
$modalInstance.close(dataToSendBack);
}
...
}
...
这会让你朝着正确的方向前进。谢谢你的评论!文件中说要使用:
}).然后(功能(项目){
$scope.items.push({id:100,nome:item.nome,email:item.email,senha:item.senha,状态:1});
});
很好 谢谢你的评论!文件中说要使用:
}).然后(功能(项目){
$scope.items.push({id:100,nome:item.nome,email:item.email,senha:item.senha,状态:1});
});
很好 若要解决此问题,请将$mdDialog.show()替换为
若要解决此问题,请将$mdDialog.show()替换为
谢谢你的评论!文档说使用:}).then(函数(item){$scope.items.push({id:100,nome:item.nome,email:item.email,senha:item.senha,状态:1});});很好!谢谢你的评论!文档说使用:}).then(函数(item){$scope.items.push({id:100,nome:item.nome,email:item.email,senha:item.senha,状态:1});});很好!
...
function MyModalCtrl($modalInstance, data){
...
function init(){
doSomethingWithDataThatYouGotFromTheCallingController(data);
}
...
function save(){
var dataToSendBack = {...};
$modalInstance.close(dataToSendBack);
}
...
}
...
$mdDialog.show({
controller: function (){
this.parent = $scope;
},
templateUrl: 'dialog1.tmpl.html',
scope:$scope.$new(),
targetEvent : ev,
bindToController: true,
clickOutsideToClose:true,
fullscreen: useFullScreen
})