如何根据在anguilarjs中使用if条件的值来加载图像

时间:2017-02-18 17:17:56

标签: javascript angularjs fusioncharts

我试图根据价值显示被占用和空置的图像。如果值大于3.50,如果等于或小于3.50,则应显示image1显示图像2。 我试过这个代码,但我无法找到我错误的地方。我没有得到任何图像。

 <td><img ng-if ng-src="{{getSlotImage(parkingslot1)}}" /></td>
    <script>
            var app = angular.module('myApp', []);
            app.controller('myCtrl', function ($scope, $http) {
                $http.get('https://example.com', {
                    headers: { 'Authorization': 'Basic 23456==' }
                })
                   .then(function (response) {
                       $scope.names = response.data;
                       $scope.decodedFrame = atob($scope.names.dataFrame);
                       $scope.decodedFrameNew = $scope.decodedFrame.substring(4);
                       $scope.distanceinFeet = 835 * 0.95;
                       $scope.Value = $scope.distanceinFeet / 148;
                       $scope.parkingslot1 = $scope.Value.toFixed(2);
                       $scope.names.timestamp = new Date($scope.names.timestamp).toLocaleString(); // Parse the date to a localized string
                   });

                $scope.getSlotImage = function (slot) {
                                       var imageUrl = slot > 3.5 ? 'http://icons.iconarchive.com/icons/custom-icon-design/flatastic-9/256/Accept-icon.png' :
                            'https://cdn3.iconfinder.com/data/icons/musthave/256/Cancel.png';


                    return imageUrl;


                }
                });


        </script>

1 个答案:

答案 0 :(得分:1)

删除标记中的ng-if属性