javascript - Angularjs - 对象未传递到指令的范围以进行双向绑定(bind)

标签 javascript angularjs angularjs-directive

这是我的指令:

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">'。这适用于其他输入,而不是这个。为什么模板中没有使用它?

最佳答案

modelinput-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/

相关文章:

php - 重新影响 div 使 jquery 表现得很奇怪

javascript - 在对 php 文件的调用之间维护 mysql 连接

html - Angularjs data-ng-repeat 不起作用

angularjs - 配置 AngularJS 模块 - 它如何影响应用程序中的其他模块?

angularjs - ngAnimate 导致错误

angularjs - 当更新一个指令中需要反射(reflect)在另一指令中的数据时,使用 $apply 是一种不好的做法吗?

javascript - 使 parent 的高度等于其 child 之一

javascript - 如何将 jQuery 函数应用于具有相同 ID 的所有元素?

javascript - 在 ng-repeat 中使用 ng-class 更改类

javascript - 使用 Angularjs 进行递归并将元素附加到 HTML 模板