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 }}
上仍然没有任何显示
最佳答案
- 在 html 中,您需要使用破折号分隔的样式,例如
getDir="location"
编写get-dir="location"
。参见 Angular Docs供引用。 - 您想打印
{{ location }}
,但在您的指令中,您将文件目标的值分配给scope.getDir
,因此您可以使用与 {{ getDir }} 相同的变量名
请查看jsfiddle中的固定码.
关于javascript - 将 Node webkit nwdirectory 绑定(bind)到 ngmodel,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24536991/