0

still learning angularJS and was thinking about dynamic loading of templates or template urls like "template: vm.getTemplate()"

I tried to find out how I can use a controllers function in the components definition.

(function() {
    'use strict';

    angular
        .module('trax')
        .component('contentLoader', {
            template: vm.getTemplate(),
            bindings: {
            },
            controller: ContentLoaderController,
            controllerAs: 'vm'
        });

    function ContentLoaderController(){

        var vm = this;

        vm.getTemplate = function getTemplate(){
            return '<div>Example Template</div>'
        }

    }

})();

Regards, n00n

n00n
  • 654
  • 1
  • 10
  • 30
  • In your example getTemplate is static. What exactly is it supposed to do in your case? It's impossible to use controller method there because controller instance doesn't exist at this point. – Estus Flask Dec 04 '17 at 20:48
  • Possible duplicate of [Angular 1.5 component method templateUrl + function](https://stackoverflow.com/questions/33841909/angular-1-5-component-method-templateurl-function) – Estus Flask Dec 04 '17 at 20:49
  • @estus I try to get a dynamic template. ContentLoader component, returns an template due to the given route. – n00n Dec 04 '17 at 20:51
  • Since this is not possible, I'd suggest to re-ask the question considering your real case. Please, provide http://stackoverflow.com/help/mcve that shows how routing and ContentLoader are supposed to work. – Estus Flask Dec 04 '17 at 20:59

0 Answers0