【问题标题】:AngularJS state not working correctly in IonicAngularJS 状态在 Ionic 中无法正常工作
【发布时间】:2016-10-28 18:11:49
【问题描述】:

我是 Ionic 的新手,state 有问题。我使用 Ionice 标签模板,但标签很少。在其中一个选项卡中,有一个指向另一个页面的链接。但是“状态”不起作用。这可能很容易,但我无法解决。

我的代码在这里(没有将它连接到 ionic,只是粘贴代码)。我希望 tab.read 工作 - 此页面的链接在 tab.dash 中。

// Ionic Starter App
angular.module('starter', ['ionic', 'starter.controllers', 'starter.services'])

.run(function($ionicPlatform) {
  $ionicPlatform.ready(function() {
    if (window.cordova && window.cordova.plugins && window.cordova.plugins.Keyboard) {
      cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true);
      cordova.plugins.Keyboard.disableScroll(true);

    }
    if (window.StatusBar) {
      StatusBar.styleDefault();
    }
  });
})

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

  $stateProvider

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

  .state('account', {
    url: '/account',
    views: {
      '': {
        templateUrl: 'templates/tab-account.html',
        controller: 'AccountCtrl'
      }
    }
  })

  .state('tab.dash', {
    url: '/dash',
    views: {
      'tab-dash': {
        templateUrl: 'templates/tab-dash.html',
        controller: 'DashCtrl'
      }
    }
  })
  .state('tab.read', {
      url: '/read/:newsId',
      views: {
        'tab-dash': {
          templateUrl: 'templates/tab-read.html',
          controller: 'ReadCtrl'
        }
      }
    })

    .state('tab.informacje', {
      url: '/informacje',
      views: {
        'tab-informacje': {
          templateUrl: 'templates/tab-informacje.html',
          controller: 'InformacjeCtrl'
        }
      }
    })

  .state('tab.zglos', {
    url: '/zglos',
    views: {
      'tab-zglos': {
        templateUrl: 'templates/tab-zglos.html',
        controller: 'ZglosCtrl'
      }
    }
  });

  $urlRouterProvider.otherwise('/tab/dash');

});
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<ion-view view-title="TestApp">
  <ion-content>

    <div class="news">

      <div class="list card" ng-repeat="item in news">
        <div class="item item-dark">
          <h2 class="light">{{ item.title }}</h2>
          <p class="dark-light">{{ item.date }}</p>
        </div>

        <div class="item item-body">
            <p>{{ item.text }}</p>
            <button href="#/tab/read/{{ item.id }}" class="button button-small button-balanced">Przeczytaj całe</button>
        </div>

      </div>

    </div>

  </ion-content>
</ion-view>

帐户也无法正常工作。但首先我必须解决 tab.read 的问题

【问题讨论】:

  • 使用ui-sref导航&lt;button ui-sref="tab.read({newsId: {{item.id}} })" class="button button-small button-balanced"&gt;Przeczytaj całe&lt;/button&gt;
  • 谢谢!有用。但是为什么我的方法没有呢?其他选项卡以这种方式工作正常。
  • 请添加其他标签的代码,以便我告诉你原因

标签: javascript angularjs ionic-framework state


【解决方案1】:

使用 ui-sref 使用 ui.router 进行导航,

<div class="item item-body">
   <p>{{ item.text }}</p>
   <button ui-sref="tab.read({newsId: {{item.id}} })" class="button button-small button-balanced">Przeczytaj całe</button>
</div>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-07-14
    • 2014-11-21
    • 1970-01-01
    • 2015-12-07
    • 2016-09-06
    相关资源
    最近更新 更多