2016-07-16 3 views
0

Ich bin schwer zu finden, warum meine Vorlage nicht geladen wird. Ich habe die Funktion $state.go verwendet, um zu meinem neuen Status zu routen. Die Funktion wird ausgeführt, aber die Vorlage scheint nicht geladen zu werden.UI-Router ist nicht Routing zu neuer Vorlage

app.js:

angular.module('starter', ['ionic', 'starter.controllers', 'ionic.contrib.ui.tinderCards', 'ui.router']) 
    .config(function ($stateProvider, $urlRouterProvider) { 

    $stateProvider 
     .state('favorites', { 
      url: '/favoritesDisplay', 
      templateUrl: 'templates/favorites.html', 
      controller: 'FavoritesCtrl' 
     }) 
     .state('login', { 
      url: '/login', 
      templateUrl: 'templates/login.html', 
      controller: 'LoginCtrl' 
     }) 
     .state('FindEvents', { 
      url: '/findEvents', 
      templateUrl: 'index.html', 
      controller: 'EventsCtrl' 
     }) 

     // if none of the above states are matched, use this as the fallback 
     $urlRouterProvider.otherwise('/favoritesDisplay'); 
    }); 

controllers.js:

angular.module('starter.controllers', []) 
    .directive('noScroll', function() { 
     return { 
      restrict: 'A', 
      link: function ($scope, $element, $attr) { 
       $element.on('touchmove', function (e) { 
        e.preventDefault(); 
       }); 
      } 
     } 
    }) 
    .controller('EventsCtrl', function ($scope, $state) { 
     var cardTypes = [ 
      { image: './images/event1.jpeg', title: 'New Apple Release' }, 
      { image: './images/event2.jpeg', title: 'Digital Conference' }, 
      { image: './images/event3.jpg', title: 'Skyline Sessions' }, 
      { image: './images/event4.jpg', title: 'Secret Rooftop Party' }, 
      { image: './images/event5.jpeg', title: 'Smoking Lights' }, 
      { image: './images/event6.jpg', title: 'Antibes Color Run' }, 
      { image: './images/event7.jpg', title: 'Tomorrowland' }, 
      { image: './images/event8.jpeg', title: 'Steve Aoki Lighting Up Town' }, 
      { image: './images/event9.jpeg', title: 'Nice Yacht Party' }, 
      { image: './images/event10.jpg', title: 'Night Pool Party' }, 
     ]; 

     $scope.cards = []; 

     $scope.addCard = function() { 
      for (var p = 0; p < 10; p++) { 
       var newCard = cardTypes[p]; 
       newCard.id = Math.random(); 
       $scope.cards.push(angular.extend({}, newCard)); 
      } 
     } 

     $scope.addCard(); 

     $scope.cardDestroyed = function (index) { 
      $scope.cards.splice(index, 1); 
     }; 

     $scope.cardSwipedLeft = function (index) { 
      console.log('Left swipe'); 
     } 

     $scope.cardSwipedRight = function (index) { 
      console.log('Right swipe'); 
     } 

     $scope.cardDestroyed = function (index) { 
      $scope.cards.splice(index, 1); 
      console.log('Card removed'); 
     } 

     //Transitioning between states 
     $scope.Favorites = function() { 
      $state.go('favorites'); 
     } 
    }); 

index.html:

<!DOCTYPE html> 
<html> 
<head> 
    <meta charset="utf-8"> 
    <meta name="viewport" content="user-scalable=no, initial-scale=1, maximum-scale=1, minimum-scale=1, width=device-width"> 
    <link rel="stylesheet" type="text/css" href="css/index.css"> 
    <title>SlidingTransitionwithAPI</title> 

    <link href="lib/ionic/css/ionic.css" rel="stylesheet"> 
    <script src="lib/ionic/js/ionic.bundle.js"> </script> 
    <script src="cordova.js"></script> 

    <script src="lib/angular-ui-router/release/angular-ui-router.js"></script> 
    <script src="lib/angular-ui-router/release/angular-ui-router.min.js"></script> 

    <script src="js/app.js"></script> 
    <script src="js/controllers.js"></script> 

    <script src="lib/ionic-ion-swipe-cards/ionic.swipecards.js"></script> 

    <script src="lib/collide/collide.js"></script> 
    <script src="lib/ionic-ion-tinder-cards/ionic.tdcards.js"></script> 


</head> 
<body ng-app="starter" no-scroll> 
    <ion-pane ng-controller="EventsCtrl"> 
     <div class="bar bar-header bar-dark"> 
      <button class="button button-clear button-icon icon ion-navicon"></button> 
      <div class="h1 title" font="6" color="white">Event Finder</div> 
      <button class="button button-clear" ng-click="Favorites()"> 
       <i class="icon ion-heart"></i> 
      </button> 
     </div> 

     <td-cards> 
      <td-card id="td-card" ng-repeat="card in cards" on-destroy="cardDestroyed($index)" 
         on-swipe-left="cardSwipedLeft($index)" on-swipe-right="cardSwipedRight($index)" 
         on-partial-swipe="cardPartialSwipe(amt)"> 
       <div class="title"> 
        {{card.title}} 
       </div> 
       <div class="image"> 
        <div class="no-text overlayBox"><div class="noBox boxed">Trash</div></div> 
        <img ng-src="{{card.image}}"> 
        <div class="yes-text overlayBox"><div class="yesBox boxed" id="centerMe">Save</div></div> 
       </div> 
      </td-card> 
     </td-cards> 
    </ion-pane> 
</body> 

Jede Hilfe wird sehr geschätzt.

+0

Wo ist dein 'Ui-View'? Sie müssen div mit dem Attribut 'ui-view' hinzufügen, um die Vorlage anzuzeigen. –

+0

isnt ui-view wird nur verwendet, wenn Sie einen Teil einer Seite laden möchten? Ich möchte, dass die Seiten ineinander übergehen. Sie sind völlig unabhängig – HerculesDev

+0

Nein, Sie müssen immer Ui-View. Wenn Sie die ganze Seite ändern möchten, setzen Sie einfach ui-view in Body-Tags. Bitte sehen Sie meine Antwort. Wenn es keine Probleme mehr gibt, akzeptieren Sie es bitte. –

Antwort

0

Sie benötigen ein ui-view-Tag, um den Inhalt der Vorlage anzuzeigen. Zum Beispiel:

<body ng-app="starter" no-scroll> 
    <div ui-view> 
</body> 

verschieben aktuellen Inhalt des Körpers an eine andere Vorlage zu bewegen (wie ‚templates/events.html‘) und dann in den Zustand Config hinzuzufügen.

Wenn Sie den Controller in der Statuskonfiguration angeben, müssen Sie nicht die ng-controller-Direktive verwenden (wie bei EventsCtrl).

+0

Danke @yariash – HerculesDev

+0

Wäre es nicht besser, ng-view zu verwenden? – HerculesDev

+0

vergiss, ion-nav-view ist etwas einfacher – HerculesDev