angularjs - How do I use different template urls for same component in angular 1.5 -
i've implemented component in following way
angular.module('modulename') .component('mycomponent', { templateurl: 'templatepath1.tpl.html', controller: mycontroller, controlleras: 'vm', bindings: { b1: '&', b2: '&' } }); i'm using <my-component b1="something1" b2="something2"></my-component>
now, want use same mycontroller template residing @ templatepath2.tpl.html.
one way create component mycomponent2,
angular.module('modulename') .component('mycomponent2', { templateurl: 'templatepath2.tpl.html', controller: mycontroller, controlleras: 'vm', bindings: { b1: '&', b2: '&' } }); is there way can use previous component , select templateurl based on attr? if yes, how should 1 that?
templateurl can function, gets element , attributes arguments:
angular.module('modulename') .component('mycomponent', { templateurl: function(element, attrs) { return 'templatepath' + attrs.x + '.tpl.html'; }, <my-component x="1"></my-component>
Comments
Post a Comment