繁体   English   中英

Angularjs Select在模式窗口中不起作用

[英]Angularjs Select doesn't work in a modal window


您好,我正在使用angularJs和bootstrap开发Web应用程序。 我在模式窗口中使用选择时遇到问题。 这是一个有效的插件文件的链接。
http://plnkr.co/edit/mcl2BMQhWRvRffvbw2nX?p=preview

只是为了让您了解我的问题。 我不能输入真实的代码,因为它是用于大学课程的。 而且我无法在插栓中制作类似的无效代码。

 angular.module('plunker', ['ui.bootstrap']); var ModalDemoCtrl = function ($scope, $modal, $log) { $scope.items = ["item1","item2","item3"]; $scope.open = function () { var modalInstance = $modal.open({ templateUrl: 'myModalContent.html', controller: ModalInstanceCtrl, resolve: { items: function() { return $scope.items; } } }); }; }; var ModalInstanceCtrl = function ($scope, $modalInstance, items) { $scope.items = items; $scope.ok = function () { $modalInstance.close($scope.items); }; $scope.cancel = function () { $modalInstance.dismiss('cancel'); }; }; 
 angular.module('plunker', ['ui.bootstrap']); var ModalDemoCtrl = function($scope, $modal, $log) { $scope.items = ["item1", "item2", "item3"]; $scope.open = function() { var modalInstance = $modal.open({ templateUrl: 'myModalContent.html', controller: ModalInstanceCtrl, resolve: { items: function() { return $scope.items; } } }); }; }; var ModalInstanceCtrl = function($scope, $modalInstance, items) { $scope.items = items; $scope.ok = function() { $modalInstance.close($scope.items); }; $scope.cancel = function() { $modalInstance.dismiss('cancel'); }; }; 

所以我的问题如下:在select标记(在视图中)中,我可以看到所有选项,但无法选择它们。
我试图放一个“。” 在我的ng-model参考中,我尝试使用父范围。 (我认为我对示波器很满意,我阅读了有关它的所有文档,在论坛上阅读了多个主题,并且尝试了很多事情)。
因此,我很确定问题不会直接来自示波器。 (此外,我不希望触发父作用域,因此它应该以正常方式工作)。

问题是,没有<select>中的ng-model,ng-options不能工作。 所以我想我的$scope.selectedItem是在某个地方创建的。 但是之后,选择被阻止,我什么也不能选择。
如果我将默认值放在$scope.selectedItem的控制器中,则会更新select标签,并且默认值似乎已被选中。 但是我还是别无选择。

您有什么想法吗?

在此先感谢您,对不起我的英语:)

我找到了解决我问题的方法。 使用引导程序,我们可以创建模式窗口,而无需在javascript文件中声明任何内容。 为此,我们必须在使用它的html文件中包含模式窗口。
这是一个显示解决方案的示例(与上面的示例不同):

这段代码打开模式:

<div ng-include="getItemTemplate('modalVariables')"></div>
<button type="button" class="btn btn-primary btn-section" data-toggle="modal" data-target="#variablesModal">Variables</button>


在模态中,我们有:

<div class="modal fade" id="variablesModal" role="dialog" aria-labelledby="modalTitle" aria-hidden="true" tabindex="-1">
<!-- content of the modal window here -->
</div>


有了这段代码,模态内部的选择对我来说是正确的。 但是我仍然不知道为什么它以前不起作用。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM