【发布时间】:2017-07-04 09:15:06
【问题描述】:
我有多次使用的组件,58 次是 exakt。它们之间唯一不同的是添加验证的独特属性。我想要做的是在编译之前向我的模板添加一组属性。这在使用 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中动态设置属性呢?
【问题讨论】:
标签: angularjs angular-components