【发布时间】:2023-03-20 19:30:01
【问题描述】:
我遇到了一个奇怪的问题,即当我尝试将 ng-show 放入我的 popover.html 时,我的应用程序挂起。当我评论它时,我的应用程序运行良好。我真的不明白我的代码中出了什么问题。
这是我的 popover.html :-
<ion-popover-view> <ion-content>
<div ng-show="showsettingButton()">
<ion-item menu-close ng-click="logout()"> Sign Out <span
class="item-icon-right"><i class="ion-chevron-right"></i></span> </ion-item>
<ion-item menu-close ui-sref="app.profile"> Settings <span
class="item-icon-right"><i class="ion-chevron-right"></i></span> </ion-item>
</div>
<div class="list" ng-repeat="title in Titlelist">
<a class="item"
ng-click="openpage(title.page_title,title.page_content)">
{{title.page_title}} </a>
</div>
</ion-content> </ion-popover-view>
这是我在控制器中的功能:-
app
.controller(
'MenuCtrl',
function($scope, LocalStorage, $stateParams, $rootScope,
$state, store, ngCart, $window, $ionicHistory,
DataService, $ionicLoading, $ionicPopup, $http,
$ionicSideMenuDelegate, $ionicPopover) {
$scope.showsettingButton = function() {
$scope.popover.hide();
if (LocalStorage.getData("userId")) {
if (LocalStorage.getData("userId") !== "undefiened") {
DataService.setbooleanIsUserLoggedIn(true);
} else {
DataService.setbooleanIsUserLoggedIn(false);
}
} else {
DataService.setbooleanIsUserLoggedIn(false);
}
return DataService.getbooleanIsUserLoggedIn()
}
$ionicPopover.fromTemplateUrl('templates/popover.html', {
scope : $scope,
}).then(function(popover) {
$scope.popover = popover;
});
$scope.openpage = function(Pagetitle, Pagecontent) {
$scope.popover.hide();
var jsonObject = {
title : Pagetitle,
content : Pagecontent
}
DataService.addcontent(jsonObject)
$state.go('app.extraPage');
}
});
如果我评论这一行
<div ng-show="showsettingButton()"> <div/>
,我的应用运行良好。
任何帮助将不胜感激
谢谢。
【问题讨论】:
-
有没有可能
LocalStorage.getData("userId")挂线了?也许它无法获取结果。 -
您能否与我们分享完整的代码(包括像
LocalStorage这样的依赖项)或者(甚至更好)添加一个 sn-p 或 fiddle? -
代替 ng-show 尝试 ng-if ..
标签: javascript angularjs ionic-framework angularjs-ng-show ionic-popover