简体   繁体   中英

AngularJS ng-show

I want to show and hide a div with ng-show directive.

Here is my HTML file:

<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:

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

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

Here is the codepen for it.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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