javascript - AngularJs打印双引号

标签 javascript angularjs asp.net-mvc

我在我的 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\';

关于javascript - AngularJs打印双引号,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40507166/

相关文章:

javascript - 在angularjs中使用ng-repeat时如何将当前月份保持在列表顶部

asp.net-mvc - 使用 GIT for Visual Studio 2012 构建克隆项目时出现问题

c# - 提供给 .NET 通用构造函数的类型参数,但仍然会导致错误,就好像没有

c# - 将对象集合添加到另一个集合

javascript - jQuery.ScrollTo 和滚动事件无法正常工作

javascript - 负面环视

javascript - 具有反应式布局的 HTML 应用程序的设计模式/工具?

javascript - 从下拉列表中选择类似的选项

Angularjs UI Bootstrap : how to vertical center modal component?

javascript - 如果用户关闭浏览器 (X) 而不是注销,如何结束 session