我已经通过以下方式实现了一个组件
angular.module('moduleName')
.component('myComponent', {
templateUrl: 'templatePath1.tpl.html',
controller: myController,
controllerAs: 'vm',
bindings: {
b1: '&',
b2: '&'
}
});
我用它作为<my-component b1="someThing1" b2="someThing2"></my-component>
现在,我想将其myController
与位于templatePath2.tpl.html
.
一种方法是创建另一个组件myComponent2
,
angular.module('moduleName')
.component('myComponent2', {
templateUrl: 'templatePath2.tpl.html',
controller: myController,
controllerAs: 'vm',
bindings: {
b1: '&',
b2: '&'
}
});
有什么方法可以使用以前的组件并根据 attr 选择 templateUrl?如果是,应该怎么做?