我有一個應用程序允許用戶在模態角材料設計對話框中創建和編輯記錄($ mdDialog) 我的問題是將對話框返回的對象放入在主控制器中的一個collecion。有沒有辦法做到這一點?把材料設計對話框中的一個對象放入主控制器
angular.module("module").controller("mainController", function ($scope, $mdDialog) {
$scope.Users = [];
function OpenEditWindow(userToEdit) {
$mdDialog.show({
templateUrl: 'Views/user.html',
controller: 'UserDialogController',
clickOutsideToClose: true,
locals: { // Envia valores para o controller do dialog
User: userToEdit
}
}).then(function (data) {
// Put the object edited into the collection on main controller, to show on the screen
$scope.Users.push(data); // ******** NOT WORKS
});
}
});
angular.module('module')
.controller('UserDialogController', function ($scope, $mdDialog, User) {
$scope.User = User;
$scope.Save = function() {
$mdDialog.hide($scope.User);
}
});