简体   繁体   English

角Js ng单击不触发?

[英]Angular Js ng-click not firing?`

Hey all I'm having the weirdest issue getting ng-click to fire in my angular app. 嘿,我遇到的最奇怪的问题是在Angular应用中触发ng-click。

Here's what I'm dealing with: 这是我要处理的内容:

<div class="popup" id="perks-popup" ng-if="perksPopup === true">

    <div class="popup-bkg" ng-click="perksPopup = false;"></div>

    <div class="popup-content">
        <div class="popup-close" ng-click="perksPopup = false;">

            <img class="scalableImg" src="img/icons/close-blue.png" alt="">

        </div>
    </div>

</div>

and here is the base controller: 这是基本控制器:

(function(){

    "use strict";

    Caribou2015.controller('BaseController', ['$rootScope', '$scope', 'Dates', function($rootScope, $scope, Dates){
        console.log('base controller init');

        //overlay and popup states
        $rootScope.welcomePopup = false;
        $rootScope.perksPopup = true;
        $rootScope.calPopup = false;


    }]);
})();

with this setup what I expect to happen is that the perks popup div will show up and when I click its background or the popup-close div, it gets removed by ngIf. 使用此设置,我希望发生的事情是会弹出特权弹出div,当我单击其背景或弹出关闭div时,它会被ngIf删除。 Well it shows up just fine but clicking the close or the background does nothing. 很好,它显示得很好,但是单击关闭或背景却无济于事。 I even added a $rootScope.$watch on the variable to see if it changes and I get nothing. 我什至在变量上添加了$ rootScope。$ watch来查看它是否更改,但我什么也没得到。 It seems like the ng click event isn't firing at all. 似乎ng click事件根本没有触发。 Is there something I'm missing? 有什么我想念的吗?

Any help would be awesome thanks! 任何帮助将是非常感谢!

-Kobby -Kobby

Don't pollute $rootScope its bad pattern, do use service/factory while you wanted to share data between various component. 不要污染$rootScope的错误模式,当您想在各个组件之间共享数据时,请使用service/factory

ng-if does create a prototypically inherited child scope on that element valued data type will not get there value populated in that div , you need to add $parent. ng-if确实在该元素值数据类型上创建了原型继承的子范围,不会在该div填充该值,您需要添加$parent. to access scope variable, before an As you are using scope variable ng-if that is causing an issue you need to follow the dot rule while declaring model, suppose that would be $scope.model={} in scope then assign all the properties and use it on html. 访问范围变量,然后在使用范围变量ng-if这引起问题时,您需要在声明模型时遵循点规则,假设范围中的$scope.model={}然后分配所有属性并在html上使用它。

Markup 标记

<div class="popup" id="perks-popup" ng-if="model.perksPopup === true">

    <div class="popup-bkg" ng-click="model.perksPopup = false;"></div>

    <div class="popup-content">
        <div class="popup-close" ng-click="model.perksPopup = false;">

            <img class="scalableImg" src="img/icons/close-blue.png" alt="">

        </div>
    </div>

</div>

Controller 调节器

$scope.model = {};
$scope.model.perksPopup = true;

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

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