【发布时间】:2018-03-05 17:00:22
【问题描述】:
我正在尝试将从 html 元素传递到父控制器(myAppController)中的函数的地址对象传递给父控制器内的控制器(即 DialogController)。我正在创建一个 md 对话框,当单击编辑按钮时,地址对象中的元素应显示在 md 对话框中。 md 对话框正在工作,但无法显示地址中的项目。 这是我的控制器
(function () {
'use strict';
angular
.module('myApp')
.controller('myAppController', myAppController);
myAppController.$inject = ['$scope', '$state','AddressesService'];
function myAppController ($scope, $state, AddressesService) {
var vm = this;
vm.addresses = AddressesService.query();
// this is a long controller so i cut short it to important part
$scope.showAdvanced = function(address, ev) {
$mdDialog.show({
controller: DialogController(address),
templateUrl: '/modules/carts/client/views/edit.tmpl.html',
parent: angular.element(document.body),
targetEvent: ev,
clickOutsideToClose:true,
fullscreen: $scope.customFullscreen // Only for -xs, -sm breakpoints.
});
function DialogController($scope, $mdDialog, address) {
console.log("address"+" "+address); // says undefined
$scope.hide = function() {
$mdDialog.hide();
};
$scope.cancel = function() {
$mdDialog.cancel();
};
$scope.answer = function(answer) {
$mdDialog.hide(answer);
};
}
};
}
}());`
这是我的html
<div ng-repeat="address in vm.addresses">
<h5 class="list-group-item-heading uppercase bold" ng-bind="address.name"</h5>
<button ng-click="showAdvanced(address, $event)">Edit</button>
</div>`
【问题讨论】: