search

Home  >  Q&A  >  body text

angular.js - Questions about $parent in angular

I found a tutorial on the Internet about angular examples. One of the examples I didn’t understand very well. I hope friends can give me some pointers:

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

The tutorial URL is: http://each.sinaapp.com/angular/tutorial/ng-nested-repeat.html

Mainly because I don’t understand:
1. On what basis are true and false determined as bool?
2. What does the following $parent.$parent.$parent.$first mean? Does it refer to scope?

Hope friends can give me some advice.

世界只因有你世界只因有你2812 days ago602

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