javascript - $state.go don't work in ionic framework -


i'm creating cordova app ionic framework, created blank app cli, in index.html have slide box, in have button in last slide. have registered click event in button, in click in button navigate templates/projects.html. hope problem clear. thanks

index.html file

  <body ng-app="starter" class="platform-android platform-cordova platform-webview">  <ion-pane>   <ion-header-bar class="bar-stable">     <h1 class="title">babylapse</h1>   </ion-header-bar>   <ion-content>       <ion-slide-box style="height:100%" on-slide-changed="slidehaschanged($index)">           <ion-slide >               <div style="height:100%" class="box blue"><h1>blue</h1>                   <img src="img/tutorial_img1.jpg">               </div>           </ion-slide>           <ion-slide>               <div class="box yellow"><h1>yellow</h1>               <img src="img/tutorial_img2.jpg">               </div>           </ion-slide>           <ion-slide>               <div class="box pink"><h1>pink</h1>                   <img src="img/tutorial_img3.jpg" class="image">               </div>           </ion-slide>           <ion-slide>               <div class="box blue"><h1>blue</h1>                   <img src="img/tutorial_img4.jpg">               </div>           </ion-slide>           <ion-slide ng-controller="firstslidectrl">               <div class="box yellow"><h1>yellow</h1>                  <!-- <img src="img/tutorial_img5.jpg" >-->                   <button style="z-index:1000;height:100px;width:100px" ng-click="go('app.projects');">créer projet</button>               </div>           </ion-slide>       </ion-slide-box>   </ion-content> </ion-pane> 

app.js file

angular.module('starter', ['ionic', 'starter.controllers', 'ngcordova'])       .config(function($stateprovider, $urlrouterprovider) {           $stateprovider                .state('app', {               url: "/app",               abstract: true,               templateurl: "index.html",               controller: 'starterctrl'            })            .state('app.projects', {               url: "/projects",               views: {                   'projects': {                       templateurl: "templates/projects.html",                       controller: 'projectsctrl'                   }               }           });           //$urlrouterprovider.otherwise('/projects');       })    .run(function($ionicplatform) {       $ionicplatform.ready(function() {           // hide accessory bar default (remove show accessory bar above keyboard           // form inputs)           if (window.cordova && window.cordova.plugins.keyboard) {               cordova.plugins.keyboard.hidekeyboardaccessorybar(true);           }           if (window.statusbar) {               statusbar.styledefault();           }        })   }); 

controllers.js

 angular.module('starter.controllers', ['ui.router'])     .controller("starterctrl", function($scope) {            $scope.data = {                numviewableslides: 0,                slideindex: 0,                initialinstruction: true,                secondinstruction: false             };            $scope.slidehaschanged = function(index) {                $scope.data.slideindex = index;            };            $scope.go = function(route) {                alert('1');                $state.go(route);             };         })        .controller("projectsctrl", function($scope) {             $scope.playlists = [{                title: 'reggae',                id: 1            }, {                title: 'chill',                id: 2            }, {                title: 'dubstep',                id: 3            }, {                title: 'indie',                id: 4            }, {                title: 'rap',                id: 5            }, {                title: 'cowbell',                id: 6            }];        })        .controller("firstslidectrl", function($scope, $state) {             $scope.go = function(route) {                alert(route);                $state.go('app.projects');             };         }); 

i cannot follow code i'll try recreate. in ionic/cordova should have index.html entry application.

this place bind html angular app , reference scripts.

it should have body main nav-view <ion-nav-view>:

<ion-nav-bar class="bar-positive">   <ion-nav-back-button>   </ion-nav-back-button> </ion-nav-bar>    <ion-nav-view></ion-nav-view> 

my ng-app called app can replace starter.

then have separate "pages" different views. can imagine in situation have 1 view slider , second 1 project's creation.

each view must defined in <ion-view> you're going have content <ion-content>.

i imagine you're going need states:

.state('main', {     url: '/main',     templateurl: 'main.html',     controller: 'maincontroller', })  .state('projects', {     url: '/projects',     templateurl: 'projects.html',     controller: 'projectscontroller', });     

if want go projects slider page have to:

$state.go('projects') 

this end result in plunker.

as can see got read of abstract view cause seems me don't need you're not using base template: side-menu or tabs.

you can add abstract should never refer index.html file.


Comments

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

php - Nothing but 'run(); ' when browsing to my local project, how do I fix this? -

php - How can I echo out this array? -