我有多次使用的組件,有58次被刪除。唯一不同的是添加驗證的唯一屬性。我想要做的是在編譯之前向我的模板添加一組屬性。當使用Angular組件時,這可能實現嗎?在Angular預編譯的組件上動態添加屬性
component.js
(function() {
'use strict';
angular
.module('upaApp')
.component('component', {
bindings: {
inputAttributes: '@',
},
controller: controller,
restrict: 'E',
templateUrl: 'app/component/component.html'
});
function controller() {
var $ctrl = this;
}
})();
component.html
<input {{ $ctrl.inputAttributes }}
class="form-control"
type="text" />
當我使用的組件<component input-attributes="directive1, directive2"></component>
它不會呈現出我的字符串,即使它,我不會相信它會工作。那麼是否有一種方法可以動態地設置AngularJS中的屬性?
這是角1,他們指出的方式是我們今天解決它的方式。我們有85個指令,所以這不是一個好的解決方案。 – user1969907
檢查我的編輯。您可能需要調整指令是否複雜。但這應該讓你去 – brhardwick