angularjs – AngularModalService:将数据传递给控制器
发布时间:2020-12-17 17:20:37 所属栏目:安全 来源:网络整理
导读:没有太多的搜索.我在这里找到了一个类似的线程,但它对我来说并不适用. 这些示例表明Modal将获得一个单独的控制器.看起来像这样. var app = angular.module('myApp',['ngSanitize','angularModalService']);app.controller('SampleController',['$scope',func
没有太多的搜索.我在这里找到了一个类似的线程,但它对我来说并不适用.
这些示例表明Modal将获得一个单独的控制器.看起来像这样. var app = angular.module('myApp',['ngSanitize','angularModalService']); app.controller('SampleController',['$scope',function($scope) { $scope.showAlert = function() { ModalService.showModal({ templateUrl: "alertWindow.html",controller: "AlertController",inputs: { title: "Add New Alert",} }).then(function(modal) { modal.element.modal(); modal.close.then(function(result) { $scope.result = "blah"; }); }); }); }]); app.controller('AlertController',function($scope) { $scope.close = function(result) { close(result,500); }; }]); 我需要注意的是,我希望模态对话框具有SampleController中的一些默认值.我读了服务,但我认为这不起作用.输入:showModal()中的{}看起来很可疑,但是一旦显示模态窗口,我就不确定从哪里获取它.我见过的其他例子只显示简单的是/否按钮或文本输入w /空默认值. 解决方法
根据文档,您将输入注入模态控制器.由于title是您在上面提到的输入,因此您可以将模态控制器更改为:
app.controller('AlertController','title',function($scope,title) { $scope.title = title; $scope.close = function(result) { close(result,500); }; }]); (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |