简体   繁体   English

AngularJS:Ng单击将参数传递到正确的Ng-show

[英]AngularJS: Ng-click passes parameter into correct Ng-show

I have an app with several modals on the page. 我在页面上有一个带有多个模式的应用程序。 What I'd like to do is have only one controller function that toggles the visibility of the modals. 我想做的是只有一个控制器功能来切换模态的可见性。 So, let's say I have the following: 因此,假设我有以下几点:

<a href ng-click="openModal(modal1)></a>
<a href ng-click="openModal(modal2)></a>

Then I'd like the modals to have something along the lines of: 然后,我希望这些模态具有以下特征:

<div class="modal" ng-show="openModal(modal1)">
<div class="modal" ng-show="openModal(modal2)">

Hope this is clear. 希望这很清楚。 I'm new to angular so kind of lost on this one. 我是新来的,所以对这一点有些迷失。 I know I can set a bunch of functions that toggle the boolean of that specific modal type, but then my controller would get big pretty fast. 我知道我可以设置很多函数来切换特定模式类型的布尔值,但是我的控制器很快就会变大。 I'd like to keep it as concise and clean as possible. 我想让它尽可能简洁明了。 Thank you in advance for your time. 预先感谢您的宝贵时间。

angular.module('ngToggle', [])
.controller('AppCtrl',['$scope', function($scope){
    $scope.custom = true;
    $scope.toggleCustom = function() {
        $scope.custom = $scope.custom === false ? true: false;
    };
}]);

Use ng-toggle and do an ng-toggle. 使用ng-toggle并执行ng-toggle。 It works on-click and you'll just need to set the property for each modal and then pass it in. So, something like.. 它可以在单击时工作,您只需要为每个模态设置属性,然后将其传递即可。

$scope.modal1visibility = true;
$scope.modal2visibility = false;

Then you should just be able to pass in those individual properties to the toggle functions and that should do what you're wanting it to do. 然后,您应该只需要将这些单独的属性传递给切换功能,即可完成您希望它执行的操作。 Hope I understood your question and that this helps 希望我理解您的问题,对您有帮助

http://www.bennadel.com/blog/2806-creating-a-simple-modal-system-in-angularjs.htm this link looks like it might be what you're talking about. http://www.bennadel.com/blog/2806-creating-a-simple-modal-system-in-angularjs.htm此链接看起来可能是您在说的。 I think I may have misunderstood after some further looking.. 经过一些进一步的研究,我认为我可能会误解了。

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

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