【问题标题】:Ionic/AngularJS can't get states or controller to workIonic/AngularJS 无法让状态或控制器工作
【发布时间】:2018-04-12 02:29:05
【问题描述】:

我对 ionic 中的标签有疑问。我正在 Ionic v1 中创建一个基本的酒店应用程序作为学校项目,但我无法让我的标签或控制器工作。未找到状态,它立即将我定向到 $urlRouterProvider.otherwise 中提供的链接。我密切关注了我的教师标签示例以及在 Ionic 中启动新标签项目时找到的示例。大约两天前我确实让它工作了一段时间,但是当我今天回到项目时它只是空白(除了我在索引文件 nav-view 中键入的内容)。

这是我的 app.js 文件

angular.module('sthlmBB', ['ionic', 'sthlmBB.controllers'])

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

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

.state("tabs.home", {
  url: "/home", 
  views: {
    "home-tab": {
     templateUrl: "templates/home.html",
     controller: "HotelCtrl"
  }
}
})

.state("tabs.bookings", {
  url: "/bookings",
  views: {
    "bookings-tab": {
     templateUrl: "templates/bookings.html",
     controller: "BookingsCtrl"
  }
}
})

.state("tabs.events", {
  url: "/events",
  views: {
    "events-tab": {
    templateUrl: "templates/events.html",
    controller: "EventsCtrl"
  }
}
});

$urlRouterProvider.otherwise("/tabs/home");

})

controllers.js

angular.module('sthlmBB.controllers', [])

.controller('HotelCtrl', function($scope, $http, $state){
  var url = 'link to php file';
  $http.get(url).success(function(response){
  $scope.rooms = response.data;

  console.log('HotelCtrl Test')
  console.log($state);
})

$scope.data = { };

$scope.submit = function(){
  var url = 'link to another php file';
  $http.post(url, $scope.data)
    .then(function(response){
      $scope.response = response;
      console.log($scope.response);
    });
}
})

在 index.html 文件中,我在头部有一个指向 app.js 和 controllers.js 的链接,在正文中有一个 ion-nav-view。

tabs.html

<ion-tabs class="tabs-icon-top tabs-color-active-positive">

  <ion-tab title="Home" icon="ion-home" href="#/tab/home">
    <ion-nav-view name="home-tab"></ion-nav-view>
  </ion-tab>

  <ion-tab title="My Bookings" icon="ion-home" 
  href="#/tab/bookings">
    <ion-nav-view name="bookings-tab"></ion-nav-view>
  </ion-tab>

  <ion-tab title="Events" icon="ion-home" 
  href="#/tab/events">
    <ion-nav-view name="events-tab"></ion-nav-view>
  </ion-tab>
</ion-tabs>

我对此很陌生,所以很可能只是某个地方的新手错误。如果能得到任何帮助,我将不胜感激!

【问题讨论】:

    标签: javascript angularjs ionic-framework web


    【解决方案1】:

    这是 app.js 在第一个状态下的拼写错误,其中 url 应该是 '/tabs',但它应该是 '/tab'。 掌心

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-12-06
      • 1970-01-01
      • 1970-01-01
      • 2013-02-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-06-14
      相关资源
      最近更新 更多