This is a weird one and I'm just about giving up on it. I'm making an app in Ionic, and it allowed me to add states just fine, like this:
$stateProvider
.state('menu', {
url: "/menu",
templateUrl: "templates/menu.html",
controller: "mainCtrl"
})
.state('products', {
url: "/products",
templateUrl: "templates/products.html",
controller: "productsCtrl"
})
etc. I have a few states there and it was all working fine a couple of days ago. I came back to the project today and added a new state - and it breaks. I added the new state the exact same way as the old ones - even copy-pasting when I saw it didn't work.
What happens is that the browser starts requesting the default over and over again (many times per second) and no template ever loads.
Now for the weird part. This is my new state:
.state('settings',{
url: "/settings",
templateUrl: "templates/settings.html",
controller: "settingsCtrl"
})
BUT when I change the templateUrl
to template
and insert directly the entire contents of the template file - it works perfectly.
That template file is located in the exact same location as the others which do work and don't break the app.
Update:It also works if I make templateUrl
a function which returns the absolute path to the file (though not the relative one like the others have). maybe it's a caching issue somehow?
Maybe there's something else I need to do? I'm new to Ionic and to Angular.
UPDATE This is my entire app.js
angular.module('starter', ['ionic', 'starter.controllers', 'starter.services'])
.run(function($ionicPlatform) {
$ionicPlatform.ready(function() {
// Hide the accessory bar by default (remove this to show the accessory bar above the keyboard
// for form inputs)
if (window.cordova && window.cordova.plugins.Keyboard) {
cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true);
}
if (window.StatusBar) {
// org.apache.cordova.statusbar required
StatusBar.styleDefault();
}
});
})
.config(function($stateProvider, $urlRouterProvider, $locationProvider) {
$locationProvider.html5Mode({
enabled: true,
requireBase: false
});
$stateProvider
.state('menu', {
url: "/menu",
templateUrl: "templates/menu.html",
controller: "mainCtrl"
})
.state('products', {
url: "/products",
templateUrl: "templates/products.html",
controller: "productsCtrl"
})
.state('settings',{
url: "/settings",
templateUrl: function (){return "myproject/www/templates/settings.html"},
controller: "settingsCtrl"
})
.state('leads', {
abstract: true,
url: "/leads",
template: '<ion-nav-view></ion-nav-view>'
})
.state('leads.index', {
url : "",
templateUrl: "templates/leads.html",
controller: "leadsCtrl"
})
.state('leads.detail', {
url: '/{lead_id}',
templateUrl: "templates/lead.html",
controller: "leadCtrl",
resolve:
{
lead_id: function ($stateParams) {
return $stateParams.lead_id}
}
})
$urlRouterProvider.otherwise('/menu');
});