当我在图像标签中使用 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/