AngularJS NG-如果用'F'和'F'问题 [英] AngularJS ng-if problems with 'f' and 'F'

查看:148
本文介绍了AngularJS NG-如果用'F'和'F'问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

任何人都可以向我解释为什么Angularjs ngIf 指令读取'F'和'F'像 <? / p>

简单的例子不工作:

 &LT;输入类型=文本NG模型=测试/&GT;
  &LT; D​​IV NG-IF =测试&GT; {{}测试}&LT; D​​IV&GT;

如果你把'F'或'F'没有显示分区,任何其他字母或正弦波工作正常。

演示:<一href=\"http://plnkr.co/edit/wS4PqmARXG2fsblUkLpH?p=$p$pview\">http://plnkr.co/edit/wS4PqmARXG2fsblUkLpH?p=$p$pview


解决方案

ngIf 使用 toBoolean 检查<一href=\"https://github.com/angular/angular.js/blob/master/src/ng/directive/ngIf.js#L90\">internally.这里是 toBoolean 本身:

 函数toBoolean(值){
  如果(typeof运算值==='功能'){
    值= TRUE;
  }否则如果(价值和放大器;&安培;!value.length == 0){
    变种V =小写字母(+值);
    值=!(V =='F'|| v =='0'|| v =='假'|| v =='没有'|| v =='N'|| v =='[] ');
  }其他{
    值= FALSE;
  }
  返回值;
}

正如你所看到的,将是一个问题不仅与˚F信,但也与'0','没有','N'等,这是不会,虽然是固定的。然而 toBoolean 很可能在未来的版本中被删除。

在Github上查看此讨论:<一href=\"https://github.com/angular/angular.js/issues/1229?source=cc\">https://github.com/angular/angular.js/issues/1229?source=cc

Can anybody explain to me why Angularjs ngIf directive reads 'f' and 'F' like false?

Simple example which does not work:

  <input type="text" ng-model="test" />
  <div ng-if="test">{{test}}<div>

If you put 'f' or 'F' nothing shows in div, any other letter or sine works ok.

Demo: http://plnkr.co/edit/wS4PqmARXG2fsblUkLpH?p=preview

解决方案

ngIf uses toBoolean check internally. Here is toBoolean itself:

function toBoolean(value) {
  if (typeof value === 'function') {
    value = true;
  } else if (value && value.length !== 0) {
    var v = lowercase("" + value);
    value = !(v == 'f' || v == '0' || v == 'false' || v == 'no' || v == 'n' || v == '[]');
  } else {
    value = false;
  }
  return value;
}

As you can see, there will be an issue not only with f letter, but also with '0', 'no', 'n', etc. It's not going to be fixed though. However toBoolean is likely to be removed in future versions.

See this discussion on Github: https://github.com/angular/angular.js/issues/1229?source=cc

这篇关于AngularJS NG-如果用'F'和'F'问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆