简体   繁体   English

ng-show 不显示下拉项

[英]dropdown items are not showing with ng-show

I am trying to show and hide dropdown item when the icons clicks but it is not showing the dropDown list.我试图在单击图标时显示和隐藏下拉项,但未显示下拉列表。 Here is my code.这是我的代码。

<div ng-click="showDropDown()" class="dropDown">
    <i style="font-size:25px" class="fa fa-folder-o"> </i>
    <div ng-show="showDropDownContents" id="myDropDown" class="dropDownContent">
        <label class="dropDownItem" ng-click="moveItem()">Item1</label>
        <label class="dropDownItem" ng-click="moveContents()">Item2</label>
    </div>
</div>

Here is my controller:这是我的控制器:

$scope.showDropDownContents = false; //Initialised to false.
$scope.showDropDown = function() {
    $scope.showDropDownContents = !$scope.showDropDownContents;
};

Try creating an object and add showDropDownContents to that object.尝试创建一个对象并将 showDropDownContents 添加到该对象。 Something like:类似的东西:

$scope.viewModel = {
   showDropDownContents: false
} 
$scope.showDropDown = function() {
   $scope.viewModel.showDropDownContents = false
}

<div ng-show="viewModel.showDropDownContents" id="myDropDown" class="dropDownContent">
        <label class="dropDownItem" ng-click="moveItem()">Item1</label>
        <label class="dropDownItem" ng-click="moveContents()">Item2</label>
    </div>

Here's a link that will be useful to clarify why: http://www.codelord.net/2014/05/10/understanding-angulars-magic-dont-bind-to-primitives/这是一个有助于澄清原因的链接: http : //www.codelord.net/2014/05/10/understanding-angulars-magic-dont-bind-to-primitives/

Your Code works 4.0 here你的代码在这里工作 4.0

Perhaps you have a JS error in your console that is crashing your app.也许您的控制台中有一个 JS 错误导致您的应用程序崩溃。 Check your console and let us know.检查您的控制台并告诉我们。 Also, check out this code pen and see why it works, but your code does not.另外,请查看此代码笔并了解它为什么起作用,但您的代码却不起作用。

Your same code posted to codepen您发布到 codepen 的相同代码

$scope.showDropDownContents = false; //Initialised to false.
$scope.showDropDown = function() {
$scope.showDropDownContents = !$scope.showDropDownContents;
};

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

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