Skip to content
This repository has been archived by the owner on May 29, 2019. It is now read-only.

Modal templateUrl can't be a function like UI-Router supports #2296

Closed
kevinrenskers opened this issue Jun 4, 2014 · 3 comments
Closed

Modal templateUrl can't be a function like UI-Router supports #2296

kevinrenskers opened this issue Jun 4, 2014 · 3 comments

Comments

@kevinrenskers
Copy link

I want to open a modal with a different template depending on the type of object I'm dealing with, but this seems impossible. The template option only takes a string.

$stateProvider.state('tasks.detail', {
        parent: 'tasks.list',
        url: '/{taskId:[0-9]{1,8}}',
        onEnter: function($modal, $stateParams, $state, tasks) {
            $modal.open({
                size: 'lg',
                controller: 'TaskDetailCtrl as controller',
                template: function($http, task, $templateCache) {
                    var templateUrl = 'tasks/' + task.type + '.html';
                    return $http.get(templateUrl, {cache: $templateCache}).then(function (result) {
                        return result.data;
                    });
                },
                resolve: {
                    task: function() {
                        return tasks.get($stateParams.taskId);
                    }
                }
            });
        }
    });

The template will literally be "function(...". In UI-Router templateUrl can be a function instead of a string, but that doesn't work here either.

How could I achieve my goal?

@kevinrenskers
Copy link
Author

Okay I was actually able to do it like this:

$stateProvider.state('tasks.detail', {
        parent: 'tasks.list',
        url: '/{taskId:[0-9]{1,8}}',
        onEnter: function($modal, $stateParams, $state, $http, $templateCache, tasks) {
            $modal.open({
                size: 'lg',
                controller: 'TaskDetailCtrl as controller',
                template: (function() {
                    var task = _.find(tasks, {id: $stateParams.taskId});
                    var templateUrl = 'tasks/' + task.type + '.html';
                    return $http.get(templateUrl, {cache: $templateCache}).then(function (result) {
                        return result.data;
                    });
                })(),
                resolve: {
                    task: function() {
                        return tasks.get($stateParams.taskId);
                    }
                }
            });
        }
    });

Still, it's strange that templateUrl doesn't accept a function like UI-Router does.

@kevinrenskers kevinrenskers changed the title Modal template and templateUrl only accept strings? Not functions? Modal templateUrl can't be a function like UI-Router supports Jun 4, 2014
@pkozlowski-opensource
Copy link
Member

Hmm, OK, actually we could easily add a possibility to specify a function, this should be trivial to add. Fancy a PR? If not I can probably push a fix later today.

@kevinrenskers
Copy link
Author

Sorry, I'm still behind on reviewing pull requests on my own projects. I could maybe find time to create one sometime later this week, but it's probably a lot quicker if you could do it? Thank you!

dearlordylord pushed a commit to dearlordylord/bootstrap that referenced this issue Jun 18, 2014
dearlordylord pushed a commit to dearlordylord/bootstrap that referenced this issue Jun 18, 2014
jurassic-c pushed a commit to jurassic-c/bootstrap that referenced this issue Aug 6, 2014
OronNadiv pushed a commit to lanetix/bootstrap that referenced this issue Nov 18, 2014
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants