【发布时间】:2013-11-30 02:45:29
【问题描述】:
现在我使用 nodejs 并研究 angularjs 以获得乐趣)但是我有一些问题我想为我的博客项目添加文件上传并且我做到了)所以我只想在用户选择某个文件时才显示上传按钮。这不是 jQuery 的问题,但我想知道如何使用 Angular 来做到这一点。所以这里我有更多的问题
这里是翡翠模板
form(method="post",enctype="multipart/form-data", action="/imageUpload")
label Select image
input(type='file',name='image',onchange="angular.element($(this)).scope().inputChange()")
button.btn.btn-primary(type='submit,ng-disabled='{{isEnable}})#uploadBtn Upload Image
这是我的工作 jQueryCod 进行验证
function UserController($scope)
{
var sizeInput = $("input[type='file']").val().length;
isEnable = sizeInput === 0 ;
$( "#uploadBtn" ).toggle( isEnable )
$scope.inputChange = function(){
sizeInput = $("input[type='file']").val().length;
isEnable = !(sizeInput > 0);
$( "#uploadBtn" ).toggle( isEnable );
}
}
当然我只能使用 jquery - 但我想知道 angular 是如何工作的。
所以我想使用 ng-disbled - 但它不能正常工作。在第一次加载时,它的位置为 true - 这一切 - 它不会改变
function UserController($scope)
{
var sizeInput = $("input[type='file']").val().length;
$scope.isEnable = sizeInput === 0 ;
$scope.inputChange = function(){
sizeInput = $("input[type='file']").val().length;
myScope.isEnable = !(sizeInput > 0);
}
}
我找到了答案,我们在这里使用不是 {{ isEnable}} 而是只使用不带括号的 ng-disabled='isEnable' 但如何将其注入到玉中???
【问题讨论】:
标签: javascript node.js angularjs express pug