【问题标题】:Binding node webkit nwdirectory to ngmodel将节点 webkit nwdirectory 绑定到 ngmodel
【发布时间】:2014-08-23 14:11:02
【问题描述】:

Node-Webkit 公开了一种使用<input type='file' nwdirectory/> 选择目录的方法,但是如何将角度模型绑定到所选文件夹?

我试过了:

.directive("getDir", [function () {
    return {
        scope: {
            getDir: "="
        },
        link: function (scope, element, attributes) {
            element.bind("change", function (changeEvent) {
                scope.$apply(function () {
                    scope.getDir = changeEvent.target.files[0]
                })
            })
        }
    }
}])

在控制器的 HTML 上(路由部分):

{{ location }}

<div class="uk-form-file">
    <button class="uk-button">New Location</button>
    <input type="file" getDir="location" nwdirectory>
</div>

实际控制人:

.controller('HomeCtrl', function($scope) {

})

但选择后{{ location }}上仍然没有显示

【问题讨论】:

    标签: javascript node.js angularjs node-webkit


    【解决方案1】:
    1. 在 html 中,您需要使用破折号分隔样式,例如,而不是 getDir="location"get-dir="location"。参考Angular Docs
    2. 您想要打印 {{ location }},但在您的指令中,您将文件目标的值分配给 scope.getDir,因此您可以使用相同的变量名称打印它,例如 {{ getDir }}

    请检查jsfiddle中的固定代码。

    http://jsfiddle.net/aleksanyan/t34L60n1/29/

    【讨论】:

      猜你喜欢
      • 2015-04-22
      • 2021-10-18
      • 2012-04-05
      • 2019-10-02
      • 2020-04-02
      • 2014-12-19
      • 2017-10-19
      • 1970-01-01
      • 2017-07-19
      相关资源
      最近更新 更多