【发布时间】:2015-03-15 13:26:45
【问题描述】:
我是 angularJs 的新手。我正在尝试创建包含输入元素和按钮的新指令。我想在单击按钮时使用此指令清除输入文本。
当我在 html 中使用我的指令时,出现以下错误:
Error: [$compile:tplrt] Template for directive 'cwClearableInput' must have exactly one root element.
html:
<div class="input-group">
<cw-clearable-input ng-model="attributeName"></cw-clearable-input>
</div>
clearable_input.js:
angular.module('cw-ui').directive('cwClearableInput', function() {
return {
restrict: 'EAC',
require: 'ngModel',
transclude: true,
replace: true,
template: '<input type="text" class="form-control"/><span class="input-group-btn"><button type="button" class="btn" ng-click="" title="Edit"><span class="glyphicon-pencil"></span></button></span>',
controller: function( $scope ) {
}
};
});
我无法弄清楚如何实现这一目标。
【问题讨论】:
标签: javascript angularjs angularjs-directive