[英]AngularJS - ng-show with ng-click not working
I am writing a simple AngularJS app, that retrieves some data from openWeatherAPI and return some values. 我正在编写一个简单的AngularJS应用,该应用从openWeatherAPI检索一些数据并返回一些值。
Now I want to be able to display the air temperature in either celsius or fahrnheit. 现在,我希望能够以摄氏度或fahrnheit显示气温。 I figured I'd do this using
ng-show
and ng-click
. 我想我会使用
ng-show
和ng-click
做到这一点。 Somehow I can't seem to get it to work. 我似乎无法以某种方式使其工作。
What I do is define a variable called stopinje like this: $scope.stopinje = true;
我要做的是定义一个名为stopinje的变量,如下所示:
$scope.stopinje = true;
. 。 Then I want to change this to false using ng-click, so when a user clicks a button, the celsius degrees will disappear, and the fahrnheit ones will appear.
然后,我想使用ng-click将其更改为false,因此,当用户单击按钮时,摄氏温度将消失,而fahrnheit数将出现。
My HTML: 我的HTML:
<li ng-show="{{!stopinje}}">{{ fahrnheit }}</li>
<li ng-show="{{!stopinje}}"><button ng-click="stopinje = true">show temperature in celsius</button></li>
<li ng-show="{{stopinje}}">{{ celsius }} °C</li>
<li ng-show="{{stopinje}}"><button ng-click="stopinje = false">show temperature in fahrnheit</button></li>
My controller: 我的控制器:
$scope.stopinje = true;
The ng-show
directive doesn't like the {{ }}
syntax. ng-show
指令不喜欢{{ }}
语法。 Just provide it an expression directly: 只需直接提供一个表达式即可:
<li ng-show="!stopinje">{{ fahrnheit }}</li>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.