简体   繁体   English

ionic $ state.go无法加载页面或显示错误

[英]ionic $state.go not loading page or showing error

I'm using $state.go() other places in my app but it's not working in a simple function and I can't work out why. 我在应用程序的其他地方使用了$ state.go(),但它无法在简单的函数中正常工作,所以我无法弄清原因。 It's not showing an error or showing the right state called in $state.go(). 它没有显示错误,也没有显示在$ state.go()中调用的正确状态。

I've tested it with $stateChangeStart, $stateChangeError, $viewContentLoading & $stateChangeSuccess. 我已经用$ stateChangeStart,$ stateChangeError,$ viewContentLoading和$ stateChangeSuccess对其进行了测试。 It reaches all the correct stages: $stateChangeStart, $viewContentLoading then $stateChangeSuccess with the right content in each however, doesn't load the page. 它到达所有正确的阶段:$ stateChangeStart,$ viewContentLoading然后$ stateChangeSuccess中每个内容正确,但是不会加载该页面。

I originally tried it with ui-sref and that didn't work so I tried it with $state.go() and now that isn't working I'm really confused. 我最初是使用ui-sref尝试过的,但是没有用,所以我用$ state.go()进行了尝试,现在却不起作用,我真的很困惑。 I can't see any difference between this code and what I have in other places where $state.go() works. 我看不到这段代码与$ state.go()工作在其他地方的代码之间的任何区别。

HTML link: HTML链接:

<li ng-repeat="thing in things" class="item" ng-click="showThingDetails()">

Code in controller: 控制器中的代码:

$scope.showThingDetails = function () {
$state.go('thingDetails');}

Code in state: 代码状态:

.state('thingDetails', {
url: '/thingDetails',
views: {
  'menuContent': {
    templateUrl: 'templates/thingDetails.html',
    controller: 'thingDetails'
  }
}
})

thingDetails.html ThingDetails.html

<ion-view view-title="Thing Details">
  <ion-content>
    <h1>{{title}}</h1>
  </ion-content>
</ion-view>

thingDetails.js ThingDetails.js

angular.module('controllers')
  .controller('thingDetails', function($scope, $stateParams) {
    $scope.title = "thing";
});

I've just found the answer to my own problem. 我刚刚找到了解决自己问题的答案。 I had copied the state from another place in my app and defining the templateUrl and controller in the views object was causing it to play up. 我已经从我的应用程序的另一个位置复制了状态,并在views对象中定义了templateUrl和controller导致了状态的出现。 I took templateUrl and controller out of the views object and it worked. 我从视图对象中取出了templateUrl和controller,它起作用了。

Code in state is now as below and works: 状态代码现在如下所示,并且可以正常工作:

.state('sweepstakeDetails', {
  url: '/sweepstakeDetails',
  templateUrl: 'templates/sweepstakeDetails.html',
  controller: 'sweepstakeDetails'
})

If anyone can add a more detailed answer as to why then I'd appreciate it. 如果有人可以针对原因添加更详细的答案,那么我将不胜感激。

Do you have an ui-view called 'menuContent' where the view should be loaded? 您是否有一个名为“ menuContent”的用户界面视图,应在其中加载该视图?

Else you could try to use this state without the menuContent views 否则,您可以尝试在没有menuContent视图的情况下使用此状态

.state('thingDetails', {
    url: '/thingDetails',
    templateUrl: 'templates/thingDetails.html',
    controller: 'thingDetails'  
})

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

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