简体   繁体   English

AngularJs打印双引号

[英]AngularJs printing double quotation

I am using AngularJs in my MVC application, I am kinda new to AngularJs. 我在MVC应用程序中使用AngularJs,对AngularJs有点陌生。 I am having a problem and couldnt find it out. 我遇到问题,无法找到答案。 AngularJs prints double quotation inside html. AngularJs在html内打印双引号。 here is my sample code. 这是我的示例代码。

What am I doing wrong? 我究竟做错了什么?

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

and this is how I set the variable. 这就是我设置变量的方式。

$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);
            })

You can do something like this 你可以做这样的事情

Use ng-src 使用ng-src

In HTML: 在HTML中:

    <img ng-src="{{condition_image}}" />

In Angularjs code: 在Angularjs代码中:

 $scope.condition_image = '~/Images/Weather/wi-yahoo-' + test + '.png\';

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

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