gpt4 book ai didi

javascript - AngularJS Material mdDialog 并在模板中显示局部变量

转载 作者:行者123 更新时间:2023-11-30 15:06:00 25 4
gpt4 key购买 nike

生成 mdDialog 的 Controller 部分看起来像

$scope.removeAttendee = function(item) {

console.log(item);

$mdDialog.show({
controller: DialogController,
templateUrl: 'views/removeMsg.tmpl.html',
parent: angular.element(document.body),
clickOutsideToClose:true,
controllerAs: 'ctrl',
fullscreen: $scope.customFullscreen, // Only for -xs, -sm breakpoints.
locals: {item: item}
})

mdDialog 的 Controller :

function DialogController($scope, $mdDialog) {

var attendee = this;

$scope.hide = function() {
$mdDialog.hide();
};

$scope.cancel = function() {
$mdDialog.cancel();
};

$scope.save = function(response) {
$mdDialog.hide(response);
};

$scope.remove = function(response) {
$mdDialog.hide(response);
};

}

removeMsg.tmpl.html 有那个代码

<p>You are going to remove {{ ctrl.item.firstName }} {{ ctrl.item.lastName }} from the lunch list.</p>

但是我无法显示相关值,即使我将代码更改为类似

的简单代码
locals { item: "test" }

和相关部分

{{ ctrl.item }}

为什么我没有显示这些值有什么建议吗?

最佳答案

由于您使用 DialogControllercontrollerAs 别名,您应该将解析值分配给 Controller 上下文 item 变量

function DialogController($scope,$mdDialog,item){//Item value will resolve via locals
var attendee = this;
attendee.item = item; // this line is important.

$scope.hide = function() {
$mdDialog.hide();
};

$scope.cancel = function() {
$mdDialog.cancel();
};

$scope.save = function(response) {
$mdDialog.hide(response);
};

$scope.remove = function(response) {
$mdDialog.hide(response);
};
}

除此之外,请将 $scope 方法转换为使用 attendee(this)。 As controllerAs 模式不鼓励在 Controller 中使用 $scope

关于javascript - AngularJS Material mdDialog 并在模板中显示局部变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45742271/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com