简体   繁体   English

ngif无法与$ scope可变角度一起使用

[英]ngif not working with $scope variable angular

I'm very new to programming and have been struggling with this issue all day. 我对编程非常陌生,整天都在为这个问题而苦苦挣扎。

I am trying to get some text to display based on wether the result of the variable 'buttons.buttonState' is 0 or 1. When I use {{buttons.buttonState}} outside of the ngif it returns the result, so I know it does actually contain the variable. 我正在尝试根据变量'buttons.buttonState'的结果为0或1显示一些文本。当我在ngif之外使用{{buttons.buttonState}}时,它返回结果,所以我知道实际上包含变量。

 <script> var fetch = angular.module('myapp', []); fetch.controller('userCtrl', ['$scope', '$http', function ($scope, $http) { $http({ method: 'get', url: 'dbqueries/startbuttonquery.php' }).then(function(response) { // Store response data $scope.buttons= response.data[0]; console.log($scope.buttons) }); }]); </script> 

 <body ng-app='myapp'> <div ng-controller="userCtrl"> <div>{{buttons.buttonState}} this returns the value '1'</div> <div *ngif="buttons.buttonState==='1'">on</div> <div *ngif="buttons.buttonState==='0'">off</div> </div> </body> 

Any help would be greatly appreciated! 任何帮助将不胜感激!

I think you are using angular 1, You should change *ngIf to ng-if. 我认为您正在使用角度1,应该将* ngIf更改为ng-if。

<body ng-app='myapp'>
<div ng-controller="userCtrl">
        <div>{{buttons.buttonState}} this returns the value '1'</div>
        <div ng-if="buttons.buttonState==='1'">on</div>

        <div ng-if="buttons.buttonState==='0'">off</div>
</div>
</body>

In angularjs *ngif is used as ng-if 在angularjs中*ngif用作ng-if

<div ng-if="buttons.buttonState==='1'">on</div>

<div ng-if="buttons.buttonState==='0'">off</div>

使用angularjs语法应为ng-if,将* ngIf替换为ng-if

<div ng-if="buttons.buttonState==='1'">on</div>

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

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