[英]How to use ng-if to show and hide on Boolean value
Struggling to find out what to put in the last span element where it says "I_DO_NOT_KNOW", this is my markup: 努力找出在最后一个span元素中显示“ I_DO_NOT_KNOW”的内容,这是我的标记:
<div class="row">
<div class="key" translate>Label</div>
<div class="value form-group">
<input id="myId"
class="form-control"
type="text"
name="nameAttrFoo"
ng-model="vm.myModelValue"
ng-blur="sanitizeInput(vm.myModelValue)"
required
/>
</div>
<div class="value form-group pull-right" ng-hide="formName.nameAttrFoo.$untouched">
<span class="note note-error"
ng-show="formName.nameAttrFoo.$error.required"
ng-hide="formName.nameAttrFoo.$dirty">
Required field!
</span>
<span class="note note-error" ng-if="I_DO_NOT_KNOW">
Number is bigger than this big prime!
</span>
</div>
and this is the function where I do a comparison, returning either true or false: 这是我进行比较的函数,返回true或false:
var boolie = false;
$scope.sanitizeInput = function(myModelValue) {
var toInt = parseInt(myModelValue);
var primeNr = 2147483647;
if (toInt > primeNr) {
boolie = true;
} else {
boolie = false;
}
}
feeling like a complete imbecile here as I cannot for the life of me get my user-feedback line "Number is bigger than this big prime!" 感觉就像在这里完全不稳定一样,因为我一生都无法得到用户反馈行“数字大于这个大质数!” to display. 显示。 I have tried a lot of things in the ng-if="I_DO_NOT_KNOW", please send help. 我在ng-if =“ I_DO_NOT_KNOW”中尝试了很多操作,请发送帮助。
Just put boolie
in the scope for example: 只需将boolie
放在范围内即可:
$scope.boolie = false;
$scope.sanitizeInput = function(myModelValue) {
var toInt = parseInt(myModelValue);
var primeNr = 2147483647;
if (toInt > primeNr) {
$scope.boolie = true;
} else {
$scope.boolie = false;
}
}
and then: 接着:
<span class="note note-error" ng-if="boolie">
If you don't want to set boolie
in the scope, you can call directly your function, but since it is already called on the blur event, I think that's not what you want (it must work though): 如果您不想在范围内设置boolie
,则可以直接调用您的函数,但是由于已经在blur事件上调用了它,因此我认为这不是您想要的(尽管它必须可以工作):
<span class="note note-error" ng-if="sanitizeInput(vm.myModelValue)">
Hoping this helps ;) 希望这会有所帮助;)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.