$范围VS在AngularJS VAR [英] $scope vs var in AngularJS

查看:96
本文介绍了$范围VS在AngularJS VAR的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在使用var和$ scope.varname和AngularJS都做工精细。我在想,如果有两个功能,什么最好的做法是在使用哪一个?

I've been using var and $scope.varname and both work fine in AngularJS. I was wondering if there was a difference between the two functionally, and what best practice was in which one to use?

推荐答案

是的! $范围变量绑定到视图,为 VAR 不和是本地的它在声明的功能!

Yes! $scope variables bind to the view where as var does not and is local to the function it was declared in!

var x = 3;
$scope.y = 3;

{{x}} - undefined
{{y}} - 3

这篇关于$范围VS在AngularJS VAR的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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