gpt4 book ai didi

javascript - 使用 Controller 作为语法时, Controller 值不会绑定(bind)在 html 中

转载 作者:行者123 更新时间:2023-11-28 18:14:52 25 4
gpt4 key购买 nike

我使用 Controller 作为语法,并尝试在单击按钮时将数据加载到模式中

html:

<md-dialog ng-cloak class="promptIncludeExclude-options">
<md-toolbar class="promptIncludeExclude-header">
<div class="md-toolbar-tools">
<span class="title">{{vm.title}}</span>
<span flex></span>
<md-button class="md-icon-button" ng-click="dialogCartController.closeDialog()">
<span class="close-dialog">&#10005;</span>
</md-button>
</div>
</md-toolbar>
<md-dialog-content>
{{vm.body}}
</md-dialog-content>
<md-dialog-actions layout="row">
<div flex="25" flex-offset="25"><md-button ng-click="dialogCartController.closeDialog()" >{{vm.button1}}</md-button></div>
<div flex="50" flex-offset="20" ><md-button ng-click="dialogCartController.closeDialog()">{{vm.button2}}</md-button></div>
</md-dialog-actions>

Js:

(function() {
'use strict';

module.exports = ['$mdDialog', 'items', function($mdDialog, items) {
debugger
var vm = this;
var data = [{
"id": 1,
"title": "Product Inclusion Notification",
"body": "something",
"button1": "proceed",
"button2": "No Thanks"
}

];
angular.forEach(data, function(value, key){
if(value.id==parseInt(items)){
vm.title=value.title;
vm.body=value.body;
vm.button1=value.button1;
vm.button2=value.button2;
}
});
vm.closeDialog = function() {
$mdDialog.hide();
};

}];
})();

按钮点击功能:

vm.handleCartOptions = function(data) {debugger

$mdDialog.show({
clickOutsideToClose: false,
scope: $scope, // use parent scope in template
preserveScope: true, // do not forget this if use parent scope
template: require('./promptIncludeExcludeDialog/promptIncludeExclude.dialog.html'),
controller: require('./promptIncludeExcludeDialog/promptIncludeExclude.dialog.js'),
controllerAs: "dialogCartController",
locals: {
items: data// on click button value
}
});

}

但是标题、正文和按钮的值并没有绑定(bind)到 html

如有任何帮助,我们将不胜感激

最佳答案

您定义了 controllerAs: "dialogCartController" 但尝试引用 vm.title

尝试使用 dialogCartController.titlecontrollerAs: "vm" 来代替。

关于javascript - 使用 Controller 作为语法时, Controller 值不会绑定(bind)在 html 中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40903662/

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