html - ng-if 是否适用于 img 标签

标签 html angularjs

当我在图像标签中使用 ng-if 时,这段代码是否有效

index.html

<img class="image" src="location.png" ng-click="openModal('locationPage')" ng-model="location" ng-init="location = true">
<img class="image" src="weather.png" ng-click="openModal('weatherPage')" ng-model="weather" ng-init="weather = true">

location.html

<div ng-if="location">
     <h2>Latitude: {{lat}}</h2>
     h2>Longitute: {{long}}</h2>
</div>
<div ng-if="weather">
    <div class="list card">
        <div class="item item-body">
          <h1 class="">{{weather.name}}</h1>
          <p class="temparature" ng-bind="{{weather.main.temp}}">Temperature: </p>
          <p class="temparature">Temperature:{{weather.main.temp_min}}</p>
          <p class="temparature">{{weather.main.temp_max}}</p>
          <p class="temparature">{{weather.main.pressure}}</p>
          <p class="temparature">{{weather.wind.speed}}</p>
          <p class="temparature">{{weather.main.humidity}}</p>
        </div>
    </div>
</div>`

最佳答案

改成这样

<img class="image" src="location.png" ng-click="location=true; openModal('locationPage')">
<img class="image" src="weather.png" ng-click="weather=true; openModal('weatherPage')">

如果您想初始化这些值,请在您的 Controller 中执行。

关于html - ng-if 是否适用于 img 标签,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42265546/

相关文章:

html - 防止容器 div 覆盖 Bootstrap 中的绝对相对 div

javascript - 隐藏 URL ui-sref (ui.router) 中的参数

javascript - 在 AngularJS 中,jquery 附加方法似乎不适用于指令

angularjs - 顺序 Angular stateProvider 解析

html - 为水平菜单创建垂直子菜单

javascript - 谷歌涂鸦是如何工作的?

javascript - 与 uib-datepicker-popup 一起使用时,uib-popover 不会消失

angularjs - AngularJS 中 $scope.$apply 的 'this' 等价物是什么?

html - 溢出前后的高度变化

html - 居中两个 div 在父容器中向左浮动