将输入值传递给$mdDialog
Pass input value to $mdDialog
我正在尝试将表单输入传递到对话框(例如标题(。问题是:它没有得到形式$scope
。
如果我在控制器中设置$scope
,它将显示正常(例如,请参见$scope.text
(。但是,如果我尝试获取表单$scope
(请参阅`$scope.taskTitle(,它就不会显示任何内容。查看我的代码:
JavaScript
app.controller('tasksCtrl', ['$scope', '$mdDialog', function($scope, $mdDialog){
$scope.teste = 'Just a test, dude';
$scope.expandTask = function() {
$mdDialog.show({
clickOutsideToClose: true,
controller: DialogController,
scope: $scope,
preserveScope: true,
templateUrl: 'models/dialog.tmpl.php',
locals: {
id: $scope.tasklist.id,
title: $scope.taskTitle
}
});
}
function DialogController($scope, $mdDialog, id, title) {
$scope.id = id;
$scope.title = title;
$scope.hide = function() {
$mdDialog.hide();
};
$scope.cancel = function() {
$mdDialog.cancel();
};
}
}]);
HTML
<div class="input-container float-icon" flex="100" layout="row" ng-repeat="task in tasklist">
<md-input-container flex="100">
<label>New Task...</label>
<input type="text" ng-model="taskTitle" name="taskTitle">
<md-button aria-label="Expandir Tarefa" class="md-icon-button expand-icon" ng-click="expandTask()">
<md-tooltip hide-sm>Expand Task</md-tooltip>
<i class="fa fa-expand"></i>
</md-button>
</md-input-container>
{{taskTitle}}
</div>
您应该将task
对象从ng repeat传递到ng click。
对于前ng-click="expandTask($event, task)"
在$mdDialog控制器中,您将可以访问该对象:
app.controller('tasksCtrl', ['$scope', '$mdDialog', function ($scope, $mdDialog) {
$scope.expandTask = function (e, task) {
//ng-click="expandTask($event, task)"
$mdDialog.show({
clickOutsideToClose: true,
controller: function ($mdDialog) {
var vm = this;
vm.task = {};
vm.task = task; //your task object from the ng-repeat
$scope.hide = function () {
$mdDialog.hide();
};
$scope.cancel = function () {
$mdDialog.cancel();
};
},
controllerAs: 'modal',
templateUrl: 'models/dialog.tmpl.php',
parent: angular.element(document.body),
targetEvent: e
});
};
}]);
在模式模板中,您将使用controllerAs表示法访问任务对象,例如:
<h1> {{ modal.task.name }} <h1>
保持最小值
并创建一个具有范围变量的控制器
$scope.expandTask = (e, task) =>
$mdDialog.show({
templateUrl: 'dialog.template.html',
controller: $scope => $scope.taskName = task.name
})
taskName
现在是$scope
变量,可以在对话框模板
相关文章:
- 为什么不't Javascript对我的输入值进行了一些重新检查
- 可以't让我的if语句处理js中的html表单输入
- 名称输入的索引
- 如何编写HTML输入的JS内联
- 要求输入在数据列表中
- 将输入字段中的文本提交到我的数据库,同时将其添加到我的列表中
- 让文本输入幻灯片显示输入时的新文本输入?然后向后滑动
- 如何将输入(type=text)从html表单传递到javascript函数
- 单击jquery清除输入值
- 而循环只设置php中输入字段中的第一个值
- 在输入字段中将最小金额设置为
- jQuery自定义验证比较多个输入的序列
- Sails.js:同时发布文本输入和一个文件
- 使用javascript检查多个输入值,并在1次检查中标记多个输入框
- 如何在输入字段中的按钮的帮助下打开日历,该字段的类型为“=”;日期”;
- 使用jquery在单击时在单元格中输入值
- Ajax文件加载和<输入>文件加载
- 是否可以将一个函数输入连接到另一个函数调用的文本
- 将值输入到对象,然后该对象推送到数组
- 将输入值传递给$mdDialog