这是我的指令:
app.directive("textareaInput", function() {
return {
restrict: 'E',
templateUrl: 'templates/directives/textarea-input.html',
replace: true,
scope: {
model: '=',
inputName: '@',
inputTitle: '@',
rows: '@'
}
}
});
这是我的模板:
<label class="item item-input">
<span class="input-label">{{ inputTitle }}</span>
<textarea name="{{ inputName }}" rows="{{ rows }}" ng-model="model"></textarea>
</label>
当我使用它时:
<textarea-input input-title="Description" model="addingPiece.desciption" input-name="desciption" rows="4"></textarea-input>
对象“addingPiece.description”没有放在模板中。它只是在 DOM 中显示为 'ng-model="model">'。这适用于其他输入,而不是这个。为什么模板中没有使用它?
最佳答案
在 model
和 input-name
两个地方传递 description
对象时指令的属性值有错别字,它应该是 description
而不是 desciption
标记
<textarea-input input-title="Description" model="addingPiece.description"
input-name="description" rows="4"></textarea-input>
关于javascript - Angularjs - 对象未传递到指令的范围以进行双向绑定(bind),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30651601/