I have a "game" where I want load a different HTML each time the same component loads.
My structure is something like
pages/game/
├── Game1-lines
│ ├── 1.html
│ ├── game.module.ts
│ └── game.ts
└── Game2-jumping
├── 1.html
├── 2.html
├── 3.html
├── game.module.ts
└── game.ts
As you can see, Game2
has 3 different HTMLs that I can use ( which I want to rotate between ). and Game1
only have 1 kind of template.
My component are loaded "lazy" and the code is something like
import { Component } from '@angular/core';
import { NavController, IonicPage } from 'ionic-angular';
let templateIndex = 1;
@IonicPage({segment: "Game2-jumping"})
@Component({
selector: 'game-page',
templateUrl: '1.html'
})
export class GameJumpPage {
templateIndex: any;
constructor(public navCtrl: NavController) {
this.templateIndex = templateIndex;
templateIndex++;
}
}
I have variable called templateIndex
which every time I load the component - is increasing ( so I always know where I left off and provide a different HTML )
Problem
The issue is with the templateUrl
, when I use templateUrl: '1.html'
- it loads 1.html
just fine.
But when I write templateUrl: templateIndex + '.html'
- it gives me error "NetworkError: 404 Not Found - http://localhost:8100/1.html"
I really don't understand what's the difference ?! between hard-coded 1.html
and variable(eq=1).html
?! ...
Any thoughts ?