Ionic / Angular:使用Master详细模式,详细信息页面不显示?

时间:2016-03-02 13:52:35

标签: javascript angularjs ionic-framework

我的应用使用标签,侧边菜单和主细节模式。但是,出于某种原因,当我尝试导航到列表中项目的详细信息页面时,没有任何内容出现。我不确定我的路由是否错误。

如果有人可以帮助我,我会非常感激!这让我发疯了!

谢谢!

app.js

.config(function($stateProvider, $urlRouterProvider) {
  $stateProvider

    .state('tabs', {
      url: '/tab',
      controller: 'TabsCtrl',
      templateUrl: 'templates/tabs.html'
    })
    .state('tabs.feed', {
      url: '/feed',
      views: {
        'tab-feed': {
          templateUrl: 'templates/tab-feed.html',
          controller: 'FeedCtrl'
        }
      }
    })  

    .state('event-detail', {
      url: '/event-detail/:name',
      templateUrl: 'templates/event-detail.html',
      controller: 'EventDetailCtrl'
    })

标签-feed.html

<ion-view view-title="Feed" class="tab-feed">
  <ion-nav-buttons side="right">
    <button class="button icon ion-funnel" ng-click="modal2.show()">
    </button>
  </ion-nav-buttons>
  <ion-nav-buttons side="left">
    <button class="button button-icon button-clear ion-navicon" ng-click="openMenu()"></button>
  </ion-nav-buttons>  
  <ion-content>
    <label class="item item-input">
    <i class="icon ion-search placeholder-icon"></i>
    <input type="search" placeholder="Search" ng-model="search">
  </label>
    <ion-list>
      <ion-item class="item item-thumbnail-left" ng-repeat="event in events | orderBy:'name' | searchEvents:search" type="item-text-wrap" href="#/event-detail/{{event.name}}">
          <img ng-src="http://placehold.it/300x300">
          <h2>{{event.name}}</h2>
          <p><i class="ion-clock"></i> {{event.date | date: 'MM/dd/yy'}} | {{event.time | date: 'shortTime'}}</p>
          <p><i class="ion-location"></i> {{event.location}}</p>
      </ion-item>

    </ion-list>
  </ion-content>

  <ion-footer-bar align-title="center" class="bar-positive">
      <div class="title" ng-click="modal.show()">Add Event</div>
  </ion-footer-bar>
</ion-view>

EventDetailsController

.controller('EventDetailCtrl', ['getLocalStorage', function($scope, getLocalStorage, $stateParams, $ionicSideMenuDelegate) {

  $scope.openMenu = function () {
    $ionicSideMenuDelegate.toggleLeft();
  };    

  var name = $stateParams.name;
  $scope.event = getLocalStorage.getEvent(name);
}])

getLocalStorage服务

.factory('getLocalStorage', function () {

    var eventList = [];

    return {
            list: eventList,

        updateEvents: function (eventsArr) {
            if (window.localStorage && eventsArr) {
                localStorage.setItem("events", angular.toJson(eventsArr));
            }
            //update the cached version
            eventList = eventsArr;
        },

        getEvents: function () {
            eventList = angular.fromJson( localStorage.getItem("events") );
            return eventList ? eventList : [];
        },

        getEvent: function(name){
            for(i=0;i<eventList.length;i++){
                if(eventList[i].name == name){
                    return eventList[i];
                }
            }
          }
    };
})

1 个答案:

答案 0 :(得分:0)

您可以尝试以下方法:

1)将abstract: true添加到您的tabs州:

.state('tabs', {
    url: '/tab',
    controller: 'TabsCtrl',
    abstract: true,
    templateUrl: 'templates/tabs.html'
})

2)在EventDetailsCtrl中,如果您正在考虑缩小,请在function...之前按顺序添加所有注射参数:

.controller('EventDetailCtrl', ['$scope', 'getLocalStorage', '$stateParams', '$ionicSideMenuDelegate', function($scope, getLocalStorage, $stateParams, $ionicSideMenuDelegate) {

如果上述方法无效,请发布您的tabs.html代码。