gpt4 book ai didi

javascript - 如何在 Angular Material 对话框内容内显示下拉列表/下拉列表/选择列表?

转载 作者:行者123 更新时间:2023-11-27 22:30:27 24 4
gpt4 key购买 nike

我对 AngularJS 还很陌生,我正在使用 Angular MaterialDialog正是自定义对话框来显示弹出对话框。

现在我可以显示对话框,但问题是我无法显示对话框 <md-dialog-content> 内的下拉菜单标签。

单击按钮时显示对话框。我从上面添加的链接复制的最小化代码:

$scope.onClicked = function(ev) {
$mdDialog.show({
controller: DialogController,
templateUrl: 'app/html/printDialog.html',
parent: angular.element(document.body),
targetEvent: ev,
clickOutsideToClose:true,
fullscreen: $scope.customFullscreen
})
.then(function(answer) {
$scope.status = 'You said the info was "' + answer + '".';
}, function() {
$scope.status = 'You cancelled the dialog.';
});
}

现在是printDialog.html(也被复制并更改文件名以满足我的需要):

<md-dialog aria-label="Print Report">
<form ng-cloak>
<md-toolbar>
<div class="md-toolbar-tools">
The toolbar or headers
</div>
</md-toolbar>

<md-dialog-content>
<div class="md-dialog-content">
All the contents goes here
</div>
</md-dialog-content>

<md-dialog-actions layout="row">
All the dialog actions goes here
</md-dialog-actions>
</form>

现在,如何在该对话框中显示带有默认选定项目的下拉可选列表。

任何帮助我都会非常感激。

最佳答案

这是一个非常简单的示例 - CodePen

标记

<div ng-controller="MyController as vm" id="popupContainer" ng-cloak="" ng-app="app">
<md-button class="md-primary md-raised" ng-click="vm.open($event)">
Open
</md-button>
<script type="text/ng-template" id="printDialog.html">
<md-dialog aria-label="Print Report">
<form ng-cloak>
<md-toolbar>
<div class="md-toolbar-tools">
The toolbar or headers
</div>
</md-toolbar>

<md-dialog-content>
<div class="md-dialog-content" layout="column">
All the contents goes here
<md-input-container>
<label>Select Beatle</label>
<md-select ng-model="chosenOption">
<md-option ng-repeat="option in options" ng-value="option">
{{option}}
</md-option>
</md-select>
</md-input-container>

</div>
</md-dialog-content>

<md-dialog-actions layout="row">
All the dialog actions goes here
</md-dialog-actions>
</form>
</md-dialog>
</script>
</div>

JS

angular.module('app',['ngMaterial', 'ngMessages', 'material.svgAssetsCache'])

.controller('MyController', function($scope, $mdDialog) {
this.open = function(ev) {
$mdDialog.show(
{
templateUrl: "printDialog.html",
clickOutsideToClose: true,
controller: DialogController,
});
};

function DialogController($scope, $mdDialog) {
$scope.options = ["john", "paul", "george", "ringo"];
$scope.chosenOption = "ringo"; // default

$scope.$watch("chosenOption", function (newValue) {
if (angular.isDefined(newValue)) {
console.log(newValue);
}
});

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

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

关于javascript - 如何在 Angular Material 对话框内容内显示下拉列表/下拉列表/选择列表?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39638129/

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