Home  >  Q&A  >  body text

angular.js - 关于angular中$parent的疑问

在网上找到一个讲angular例子的教程,其中一个例子,没怎么看懂,希望各位朋友能指点一二:

ng-class="{true: 'year-interest', false: 'etc-text'}[$parent.$parent.$parent.$first]"

教程网址在:http://each.sinaapp.com/angular/tutorial/ng-nested-repeat.html

主要是没看懂:
1、那个true和false是依据什么进行bool判断的?
2、后面的$parent.$parent.$parent.$first是什么意思,是指作用域吗?

望各位朋友能指点一二。

世界只因有你世界只因有你2687 days ago540

reply all(1)I'll reply

  • 曾经蜡笔没有小新

    曾经蜡笔没有小新2017-05-15 17:01:13

    1. true false is judged based on the following expression, that is, $parent.$parent.$parent.$first
      $first是$scope的一个属性,true代表是第一个元素,false represents the non-first element

    2. $parent refers to the parent scope, $parent.$parent is the parent scope of the parent scope, and so on.

    Why so many $parents?
    Many directives in angular such as ng-ifng-repeat will create child scopes

    reply
    0
  • Cancelreply