在扩展$ Angular.js范围 [英] Extending $scope in Angular.js

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

问题描述

有时候,我看到使用这种模式的人:

angular.extend($范围,{somekey,someval})

什么是应用范围扩展的这种风格,当我可以设置范围的利益直接像这样:

$ scope.somekey = someval


解决方案

  

什么是好处使用范围扩展的这种风格?


如果我读<一个href=\"https://github.com/angular/angular.js/blob/7757f0a9e3dff7b1feb9994d750b5251230936c8/src/Angular.js#L326\"相对=nofollow>这个正确,绝对没有,尽管语法伪糖,我personely不agreee。

不过,读了一些角单张的问题,有一天,我记得我读有人指出,一些与 angular.extend 工作,用一个简单的任务也没有。

Sometimes, i see people using this pattern:

angular.extend($scope, {somekey, someval}).

What is the benefit in using this style of scope extension, when i can set the scope directly like so:

$scope.somekey = someval?

解决方案

What is the benefit in using this style of scope extension ?

If I read this correctly, absolutely none, despite syntactic pseudo-sugar that I personely don't agreee with.

Though, reading some angular-leaflet issues, one day, I remember I read someone stating that something worked with angular.extend and didn't with a simple assignment.

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

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