Is there a way to dynamically render different templates for an angular 1.5 component Is there a way to dynamically render different templates for an angular 1.5 component angularjs angularjs

Is there a way to dynamically render different templates for an angular 1.5 component


This is not something that components were specially made for. The task narrows down to using a directive with dynamic templates. The existing one is ng-include.

To use it within a component, it should be:

var myComponentDef = {  bindings: {    type: '<'  },  template: '<div ng-include="$ctrl.templateUrl">',  controller: function () {    this.$onChanges = (changes) => {      if (changes.type && this.type) {        this.templateUrl = this.type + '.html';      }    }  }}


You can inject any service and set dynamic url

angular.module('myApp').component("dynamicTempate", {        controller: yourController,        templateUrl: ['$routeParams', function (routeParams) {                       return 'app/' + routeParams["yourParam"] + ".html";                }],        bindings: {        },        require: {        }    });