[英]View doesn't get updated when using ng-if in angular
I have buttons like this: 我有这样的按钮:
<div>
<ul>
<li ng-if="role === 'artist'"><a data-ng-click="search.status = 'PORTFOLIO'" href="">PORTFOLIO</a></li>
<li ><a data-ng-click="Data1 = true;Data2 = false; search.status = ''" href="">ALL PROJECTS</a></li>
<li ><a data-ng-click="Data1 = false;Data2 = true;" href="">NOTIFICATIONS</a></li>
<li ><a data-ng-click="Data1 = true;Data2 = false; search.status = 'COMPLETED PROJECTS'" href="">COMPLETED PROJECTS</a></li>
<li ng-if="role === 'admin'" ><a data-ng-click="Data1 = true;Data2 = false; search.status = 'OPEN'" href="">SAVED PROJECTS</a></li>
<li ng-if="role === 'admin'" ><a data-ng-click="Data1 = true;Data2 = false; search.status = 'IN PROGRESS'" href="">RUNNING PROJECTS</a></li>
<li ng-if="role === 'admin'" ><a data-ng-click="Data1 = true;Data2 = false; search.status = 'ASSETS'" href="">ASSETS</a></li>
<li ng-if="role === 'admin'" ><a data-ng-click="Data1 = true;Data2 = false; search.status = 'JOB REQUESTS'" href="">JOB REQUESTS</a></li>
</ul>
</div>
Where I am checking the role using ng-if="role=='admin'"
in the last four buttons. 我在最后四个按钮中使用
ng-if="role=='admin'"
检查角色的位置。
The problem is when I click the 3rd button(Notifications) and then click on any button where ng-if is defined then the view is not populating. 问题是当我单击第三个按钮(通知),然后单击定义了ng-if的任何按钮时,该视图未填充。
When I navigate from notifications button(3rd button) to All projects button(1st button) and then navigate to any other button that has ng-if it is working fine. 当我从通知按钮(第三个按钮)导航到所有项目按钮(第一个按钮),然后导航到其他所有具有ng-如果工作正常的按钮。
Also if I remove ng-if it is working fine. 另外,如果我删除ng-如果工作正常。 Why is this happening to only particular buttons?
为什么仅在特定按钮上会发生这种情况?
ng-repeat to populate data based on button click: ng-repeat基于按钮单击填充数据:
<div ng-if="workOrdersList.length > 0">
<ul ng-show="Data1">
<li dir-paginate="wd in workOrdersList | filter: search.status | filter: search.name | itemsPerPage: 10">
<a href="">
<h4>{{wd.name}}</h4>
</a>
<p>Status: {{wd.status}}</p>
</li>
</ul>
<ul ng-show="Data2">
<li>
<div ng-show="notificationDataDashord.length">
<h3>Notifications </h3>
<div infinite-scroll="getPagination()">
<div ng-repeat="notification in notificationDataDashord" ng-class="{even: $even, odd: $odd}" >
<strong>{{notification.user_name}}</strong>
<a href ng-click="openModal(notification.work_module_id)">{{notification.message}}</a>
</div><!--/row-->
<div ng-if="notification.image_url">
<a href="{{notification.image_url}}" target="_blank">
<img src="{{notification.image_url}}">
</a>
</div>
</div><!--/notifications-->
</div><!--/tabs conent-->
</li>
</ul>
<dir-pagination-controls boundary-links="true" ng-show="Data1" auto-hide="true"></dir-pagination-controls>
</div>
Controller: 控制器:
$scope.Data1 = true;
$scope.Data2 = false;
I suggest you try to use ng-show/ng-hide instead of ng-if in your approach. 我建议您尝试在方法中使用ng-show / ng-hide而不是ng-if。
Here is a good read When to favor ng-if vs. ng-show/ng-hide? 这是一本好书, 何时支持ng-if和ng-show / ng-hide?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.