gpt4 book ai didi

AngularJS:是 0 == 2?

转载 作者:行者123 更新时间:2023-12-04 00:34:36 25 4
gpt4 key购买 nike

这个问题在这里已经有了答案:





How to parseInt in Angular.js

(7 个回答)


5年前关闭。




我在这里挠头。我正在使用 angularJS 并尝试使用包含对 parseInt 调用的表达式。

{{0 == 2}}  

...打印出来 正如预期的那样。)

但是,当我尝试时:
{{parseInt(0) == parseInt(2)}} 

...它打印出来... !

这怎么可能?

最佳答案

Angular does not use JavaScript's eval() to evaluate expressions. Instead Angular's $parse service processes these expressions.

Angular expressions do not have access to global variables like window, document or location. This restriction is intentional. It prevents accidental access to the global state – a common source of subtle bugs.



Refer

在你的 html

两者 parseInt(0)parseInt(2)在您的 html 中未定义。

所以 {{undefined==undefined}}true .因为 parseIntJavascript功能。所以你不能访问 parseInt侧面功能 {{}} . [这里 parseInt 不是作用域变量]

解决方案

如果你想这样做,

定义 parseInt在您的 Controller 中,
$scope.parseInt = parseInt;

然后你可以使用 parseInt你的html中的方法

关于AngularJS:是 0 == 2?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37826334/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com