简体   繁体   English

AngularJS ng-show

[英]AngularJS ng-show

I want to show and hide a div with ng-show directive. 我想使用ng-show指令显示和隐藏div。

Here is my HTML file: 这是我的HTML文件:

<body ng-app="my-app">
  <div ng-controller="MainController">
    <ul ng-show="isVisible" id="context-menu"> 
      <li> Menu item 1 </li>
      <li> Menu item 2 </li>
    </ul>

  </div>
</body>

Here is my CoffeeScript file: 这是我的CoffeeScript文件:

myApp = angular.module("myApp", [])

myApp.controller "MainController", ["$scope", ($scope) ->
  $scope.isVisible = false
]

Here is the codepen for it. 这是它的codepen

What is the problem? 问题是什么? Can you help? 你能帮我吗?

The issue with your code is : 您的代码存在的问题是:

<body ng-app="my-app">

It should be: 它应该是:

<body ng-app="myApp">

Don't confuse how you define attributes with their values. 不要混淆如何使用属性值定义属性。

http://codepen.io/anon/pen/AHxEw http://codepen.io/anon/pen/AHxEw

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

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