将节点webkit nwdirectory绑定到ngmodel

Binding node webkit nwdirectory to ngmodel

本文关键字:ngmodel 绑定 nwdirectory 节点 webkit      更新时间:2023-09-26

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

我试着:

.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 }}上仍然没有显示

  1. 在html中,你需要使用虚线分隔的样式,而不是getDir="location"get-dir="location"。参考Angular Docs。
  2. 你想打印{{ location }},但是在你的指令中,你将文件目标的值分配给scope.getDir,所以你可以使用相同的变量名打印它,如{{getDir}}

请检查jsfiddle中的固定代码。

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