[英]How to use ng-disabled with jade templates
现在我工作的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',不带括号,而是将其注入玉石中?
删除{{}}
因为您已经在Angular的ng-*
属性中进行了编写:
ng-disabled='{{isEnable}}
至:
ng-disabled='isEnable'
使用ng-show
button.btn.btn-primary(type ='submit,ng-show ='isEnable')#uploadBtn上传图片
这将告诉angular仅在isEnable
为true时显示您的按钮。 如果为假,则不会显示该按钮。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.