0

So, for whatever reason, I am trying to create a slider, where the contents of each slide are different HTML templates. So instead of an image slider, you could say it's a HTML slider.

So in my HTML I just have this code, and the controls for the slider are also inside this HTML template:

<slide-template></slide-template>

And here is my entire slide module:

(function() {
    'use strict';

    angular
        .module('slideCtrl', [])

    .directive('slideTemplate', function() {
        return {
            restrict: 'E',
            templateUrl: 'views/slides/slide-1.html',
            replace: true,
            controller: 'slideController',
            controllerAs: 'slides'
        }
    })

    .controller('slideController', function() {

        var vm = this;

    });

})();

I'm not sure how to move forward with this, I've tried looking around but haven't found anything that I felt I could use. Inside the controller, I would like to have an array of slide template URLs and a corresponding variable to indicate the current slide:

slideUrl = [ 'views/slides/slide-1.html', 'views/slides/slide-2.html'];
slideNum = 0;

Ideally, I would then like my directive to use these variables to determine what variable it will use for templateUrl. So by default, you can see that slideNum is 0, meaning that I want to use slide1.html or slideUrl[0]. So, my templateUrl would be something like slideUrl[slideNum]. Of course, this can't be done as the directive wouldn't be able to access that data, so I'm not sure how to do this.

The end result would be that if you clicked one of the slide navigation icons, you would be updating the slideNum variable, which would instantly change the templateUrl used.

I guess I am essentially wanting a slider which doesn't rely on some images or something like that for content, but instead is a slider of actual HTML content.

Any ideas? If I haven't explained myself well enough, please let me know.

germainelol
  • 3,231
  • 15
  • 46
  • 82
  • Are the slide URLs always the same? Or can they change ? Interesting question by the way. – ndsmyter Jul 08 '15 at 09:06
  • @ndsmyter For now, let's just say that yes the URLs will always be the same. So, the `slideUrl` array will just be manually created by me to hold all the slides. – germainelol Jul 08 '15 at 09:07
  • Is it something like https://github.com/angular/angular.js/issues/1039 you want? – ndsmyter Jul 08 '15 at 09:11
  • possible duplicate of [Angular.js directive dynamic templateURL](http://stackoverflow.com/questions/21835471/angular-js-directive-dynamic-templateurl) – Sergiu Paraschiv Jul 08 '15 at 09:15
  • @ndsmyter I'll have a read, it seems like it could be, but I've seen some similar posts before and just seem to have difficulty actually implementing it. I also added a little update about what I'm trying to achieve too; I know a lot of sliders use some sort of content inside an `
  • ` basically, but I am essentially wanting to create a slider where the slides are just HTML templates.
  • – germainelol Jul 08 '15 at 09:15
  • I added a possible way I would do it below. Maybe that helps.. – ndsmyter Jul 08 '15 at 09:22