在我的指令中:
app.directive('ckEditor', [function () {
return {
require: '?ngModel',
link: function ($scope, elm, attr, ngModel) {
和HTML:
<textarea style="height: 350px; width: 98%"
data-ck-editor
data-editor-size="wide"
data-ng-disabled="modal.action=='delete'"
data-ng-model="modal.data.notes"
name="notes"></textarea>
有没有办法可以访问我分配给该元素的名称?
答案 0 :(得分:3)
您可以访问attr
app.directive('ckEditor', [function () {
return {
require: '?ngModel',
link: function ($scope, elm, attr, ngModel) {
console.log(attr);
console.log(attr['name']);
/* etc */
答案 1 :(得分:2)
以下任何一项/两项均应有效:
elm.attr("name")
或
attr.name