AngularJs打印双引号

AngularJs printing double quotation

本文关键字:打印 AngularJs      更新时间:2023-09-26

我在MVC应用程序中使用AngularJs,我对AngularJs有点陌生。我遇到了一个问题,却找不出来。AngularJs在html中打印双引号。下面是我的示例代码。

我做错了什么?

<div class="visible-md visible-lg col-md-3 text-right" ng-controller="WeatherController">
    <div class="weather">
        <i id="weather_icon" class="icon">
            {{condition_image}}
        </i>
        <h3>
            <span class="glyphicon glyphicon-map-marker"></span>
            <span id="cityName"></span>
            <span class="temp">
                <span>
                    {{weathers}}
                </span>
            </span>
        </h3>
        <span class="date" id="current_date">
        </span>
    </div>
</div>

,这就是我如何设置变量的

$http.get('/api/getweatherbycityname/' + $city).
            success(function (data, status, headers, config) {
                $scope.weathers = data.condition_temp + '℃ ';
                $scope.condition_image = '<img src=''~/Images/Weather/wi-yahoo-' + data.condition_code + '.png'' />';
                //document.getElementById("weather_icon").className += ' wi-yahoo-' + data.condition_code;
            }).
            error(function (data, status, headers, config) {
                //alert(data);
            })

你可以这样做

使用ng-src

在HTML中:

    <img ng-src="{{condition_image}}" />
在Angularjs代码中:
 $scope.condition_image = '~/Images/Weather/wi-yahoo-' + test + '.png'';