简体   繁体   English

Angular ng-hide / ng-show指令不起作用

[英]Angular ng-hide/ng-show directives not working

I have an issue which presents on an Android 4.x device, but not on a newer device. 我在Android 4.x设备上出现问题,但在较新的设备上却没有问题。 I have no idea why, but I'm hoping someone can help. 我不知道为什么,但我希望有人能提供帮助。

I have a list using ng-repeat . 我有一个使用ng-repeat的列表。 Each item uses ng-include to load a template dynamically (this is a generic, reusable dialog). 每个项目都使用ng-include动态加载模板(这是一个通用的可重用对话框)。

<ons-list-item ng-repeat="item in items | filter:filterItems(searchTerm) as filtered" ng-click="options.selectItem(item)" style="font-size: 14px; padding: 0;" tappable>
  <div class="left" style="width: 100%;">
    <ng-include src="'app/dialog/smartpick/'+options.itemTemplate" style="width: 100%; padding: 0px 16px;"></ng-include>
  </div>
</ons-list-item>

The template currently causing me issues contains a button like this: 当前导致我出现问题的模板包含这样的按钮:

<ons-button ng-click="openDocument(item, $event)" ng-if="item.SpecificationSpecDocumentID" style="float: right;font-size: 20px !important; padding: 0px 10px;">
    <ons-icon icon="ion-image" ng-hide="item.opening" style="vertical-align: middle;"></ons-icon>
    <ons-icon icon="ion-load-b" ng-show="item.opening" class="spin" style="vertical-align: middle;"></ons-icon>
</ons-button>
Debug: {{ item.opening }}

When openDocument is called, it does this (among other things): 调用openDocument ,它会执行此操作(除其他外):

if(item.opening) return; 
item.opening = true;

When the list is rendered, both of the <ons-icon> elements are shown; 呈现列表时,将同时显示两个<ons-icon>元素。 the ng-show / ng-hide directives do not seem to do anything. ng-show / ng-hide指令似乎什么也没做。 The debug text under the button shows true or false respectively, but no class or style is added to the icon elements. 按钮下方的调试文本分别显示true或false,但没有将类或样式添加到图标元素。 (I also tried isolating the problem by moving the directives to wrapper <span> elements, but it didn't have any effect.) (我还尝试通过将指令移至包装器<span>元素来隔离问题,但没有任何效果。)

As I said before, this work fine on a newer device. 正如我之前所说,在较新的设备上可以正常工作。 Any clues as to what may cause directives to fail or be ignored on older devices? 关于什么可能导致指令在旧设备上失败或被忽略的任何线索?

EDIT 编辑

It certainly has something to do with the child scope created inside the <ons-button> element, because the directives work outside of that scope. 它肯定与<ons-button>元素内创建的子范围有关,因为指令在该范围之外工作。 I just don't know why it would work in newer webviews but not the older one. 我只是不知道为什么它会在较新的Webview中起作用,而在较旧的Webview中却不起作用。

I still don't know what the browser version had to do with it, but it seems the problem was a consequence of using ng-if in my templates. 我仍然不知道浏览器版本与它有什么关系,但是看来问题出在模板中使用了ng-if When I changed those into ng-show , the problem disappeared. 当我将它们更改为ng-show ,问题消失了。

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

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