javascript - 将 Node webkit nwdirectory 绑定(bind)到 ngmodel

标签 javascript node.js angularjs node-webkit

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

我试过:

.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]
                })
            })
        }
    }
}])

在 Controller 的 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 }}
  3. 相同的变量名

请查看jsfiddle中的固定码.

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

关于javascript - 将 Node webkit nwdirectory 绑定(bind)到 ngmodel,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24536991/

相关文章:

javascript - 使用 javascript 修改 CSS

node.js - 单独的node-sass和Express中间件之间的性能差异

angularjs - angular.js 在包装 ng-repeat 时尝试多次迭代

javascript - <Link> 点击时卡住页面

javascript - MobX:观察到的组件在可观察到的变化后不会重新呈现

javascript - Node Js - 识别请求是来自移动设备还是非移动设备

javascript - AngularJS Linky过滤器停止传播

javascript - 当严格模式为全局时,如何在浏览器JS中启用Rollbar?

javascript - iOS 和 Android 浏览器中的多声道音频支持

node.js - 读取复选框值 Node JS + Express + Jade