由于“替换”配置通常已被弃用并且在 1.5 angular.component 中不可用,我想知道最佳实践是设置组件样式并保持高可重用性。
例子:
app.component('changePasswordButton', {
bindings: {
users: '='
},
template: '<button class="btn btn-default"
ng-disabled="vm.users.length == 0"
ng-click="vm.changePassword()">Change password</button>',
controllerAs: 'vm',
controller: [function () {
var vm = this;
vm.changePassword = function () {
//do it...
});
}]});
假设我想在将按钮与“btn-primary”一起使用时为其设置样式。
我做不到
<change-password-button class="btn-primary"></change-password-button>
因为呈现的 html 将是:
<change-password-button class="btn-primary">
<button ....>
</change-password-button>
关于如何以可扩展且良好的方式在组件(按钮)上应用上下文样式的任何想法?